last day (15 days later) » 

12:46 PM
@KevinC ow. I can't make you owner under 100 rep (join a different SE site and you'll get association bonus)
 
Ok, I'll try
 
in Lounge<C++>, 15 hours ago, by Kevin C
Hello everyone! This is my first time here. I was looking at your book recommendations (http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) and I noticed that you have only a single book in "introductory, no previous experience" category. May I propose my book "Programming for Beginners - with C++" for review? Some chapters (slightly shortened) are available online at www.programming4beginners.com .
 
@sehe I think this reputation thing will not work: "If you are an experienced Stack Exchange network user with 200 or more reputation on at least one site, you will receive a starting +100 reputation bonus to get you past basic new user restrictions. This will happen automatically on all current Stack Exchange sites where you have an account, and on any other Stack Exchange sites at the time you log in."
 
@KevinC Oh. Darn. Sorry for not knowing how the rep thing works.
 
@sehe OK. Never mind, can we have a discussion here?
 
12:54 PM
Okay. We'll have to wait with the owner thing. Anything you like changed? Anyone else who should be owner too?
@KevinC Yes
 
There is one thing which sehe said (I think it was him), which was king of bothering me.
Now, I was making an argument 'term x is used to denote foo and bar'. Then, many people started saying that 'x denotes bar'. But that does not overthrow the statement 'x denotes foo, too'. And I dont see how that is circular reasoning.
king of = kind of
 
@KevinC Nobody said it was circular reasoning.
 
@sehe Oh, ok, there was so much clutter, I must have misuderstood.
 
I was saying you were running the argument in circles. This happens when you reiterate the same things without changing the inputs. This did happen. In fact, it was 100% of what happened today (until 'using namespace std' perhaps)
 
Oh, right. Well, I had the feeling that others were doing that too, so I felt necessray to repeat my arguments which were answers to their repeated claims.
 
1:03 PM
As such, it's becoming just noise. And you've seen what happens if there's noise in a crowded room.
As an owner, I feel the responsibility to steer the argument out of the loop.
@KevinC Others were doing that too, indeed. I "blame them" too - if that changes anything :S
 
Ok, so about ' function composition'. As I said, I think that term needs to be verified. My 'feeling', which I base on the contents of the Wikipedia articles, is that the term 'function composition' is used in mathematics in a more strict sense, and in programming it is used in a wider sense. But the ulimate test will be: is the term 'function commposition' used relatively often to denote nested finction calls.
As I said, if I was wrong, I will change the tect of the book. I use that term only in a few places, it is no big deal.
 
In computer science, function composition (not to be confused with object composition) is an act or mechanism to combine simple functions to build more complicated ones. Like the usual composition of functions in mathematics, the result of each function is passed as the argument of the next, and the result of the last one is the result of the whole. Programmers frequently apply functions to results of other functions, and almost all programming languages allow it. In some cases, the composition of functions is interesting as a function in its own right, to be used later. Such a function can always...
Taking the first sentence, that should be definitive.
Just calling f(g(x)) is really just sequential application. The key difference is higher-order/first class functions.
 
I think that the wikipedia article is actually quite ambigous on the question 'what exactly can be called a function composition'. I think there are two possible ways to understand it. I suggest that we try with some other, less ambigous source.
 
> In computer science, function composition (not to be confused with object composition) is an act or mechanism to combine simple functions to build more complicated ones
What is ambiguous.
 
@sehe What exactly the term ' funcrion composition' refers to. FOr example, look at this sentence: "For example, suppose we have two functions f and g, as in z=f(y) and y=g(x). Composing them means we first compute y=g(x), and then use y to compute z=f(y)."
 
1:20 PM
Well duh. That sentence describes the behaviour once the composed function is invoked
Composition would be h = compose(f,g); (now you can use h(x) to mean f(g(x))). That's not what f(g(x)) does, because it just invokes the functions once.
You could argue that int h(int x) { return f(g(x)); } is a composition, but it's not function composition, because it's hardcoded. Also, if int h(int x) { return f(g(x)); } is a hardcoded composition, then clearly f(g(x)) is not (it's the invocation that emulate the implementation of the composition)
It's proper function composition if you could write F compose(F f, F g) { return f * g; } or so
 
Ok, I was searching a bit for the term 'function composition'. Indeed, I'm having trouble finding references where it means 'nested function calls', and the references to true functional composition are abound. It seems that using that term for 'nested function calls' has the potential of confusing beginners. So, at this moment, it is likely that I will change the term. I will investigate it some more, but at this moment, the available evidence is compeling me to do this change.
 
If we drop the strict requirement for higher-order-functions, and allow for "emulating" the semantics of composition...:
@KevinC Did you see my point of h(int x) { return f(g(x)); } ("a composition") vs. f(g(x)) ("nested invocations")?
 
Yes, I perfectly understand the difference, I just previously tought it is apropriate to use term 'function composition' for both of those.
SO, do you think that 'nested function calls' would be an appropriate term?
 
Yes.
 
Ok, so that problem solved. So, we can move to next issue.
 
1:33 PM
Yay!
 
Someone complained about 'using namespace std'
Ok, i need a small pause.
But I'll be back to answer.
 
in Lounge<C++>, 1 hour ago, by sehe
930
Q: Why is "using namespace std;" considered bad practice?

akbiggsI've been told by others on numerous occasions that my teacher was wrong in saying that we should use using namespace std; in our programs. Hence, we should use std::cout and std::cin and these are more proper. However, they did not even make it clear ever why this is a bad practice. Why is usin...

I personally don't object to judicial use of using namespace std;. But in general, it's bad teaching if it's shown in global scope/namespace level in samples. Or even worse, assumed to always be there.
 
1:51 PM
Ok, I can agree that using namespace std is a bad practice. But here is the issue: the book is for beginners. Some additional syntactic elements which might seem trivial to you and me are usually scary for beginners. So, it's not only my book that uses 'using namespace std'. For example, on 'definitive' list, the Stroustroup's book also (kind-of) does that, and the Eckel's book, too. So, if others are using it, I also took that liberty.
The biggest complaint could, perhaps, be that I didn't mention anywhere in the book that 'using namespace' is a bad practice. I might add such a notice. I'm still not quite convinced that I should use std qualifier throughout the book.
- AFK for 5 mins -
I'm going AFK for 5 mins.
 
@KevinC It's a fair liberty, as long as you make it clear that in production code it's almost always a bad idea (and why, in chapter "advanced X")
@KevinC Just use function-scope using namespace std; everywhere (makes the decision visible) and make sure using namespace is in the index
 
I can talk about it in the chapter about libraries (not available on thwe web). I can put 'using namespace' in the TOC (I don't yet have an index).
 
@KevinC Those sound like good places (index>TOC, but yeah)
 
Is 'using namespace' on the function-level safe? Doesn't it suffer from the same problems as the global directive?
 
It suffers from a subset of the same issues, but it gives the programmer very easy power to combat it. And it makes the decision a local, repeated, conscious one
By making it visible and repeated, it drives the point home, no one assumes it's always the case. Consider:
    using namespace std; // for brevity
 
2:09 PM
Hm, I'm not really happy with that. I think I would rather use the std prefix everywhere. And when I introduce Allegro, It is not really an issue anymore, as the 3rd part of the book doesn't use iostream at all (but there is still vector). Libraries are introduced at the end of the 2nd part, so it all matches quite well.
I can also use "using std::vector".
Btw, I explain namespaces here: http://www.programming4beginners.com/tutorial/chapter13/using-Directive-and-using-Declaration
and the entire next chapter (chapter 14) doesn't use 'using namespace std'. I did it there so that a beginner can better understand other materials on the internet.
 
@KevinC +1
 
Ok, I guess that would solve that issue. I think we can move to the next issue.
 
If there's one :)
 
From yesterday'd discussion, it seems there are a lot of things people don't like. For exmaple, someone complained that the first 8 chapters of the book use exlusively the type 'double' instead of type int (even as counters in for loops).
 
@KevinC I don't understand how using namespace std; is supposed to be more comforting then std::vector<int> for example.
Isn't it easier to explain that the name of a vector type is std::vector and that for all intense and purposes std::vector is the full name of said type (it's actually ::std::vector<T> but you get the point) as opposed to: "Oh yeah, we have to add using namespace std; in the top of the file".
"But what is a namespace?" -- "Don't bother with it for now"
"Do we have to repeat it in different files too?" -- "Depends on what kind of files they are"
And so on.
I think that using namespace std; raises many more questions then explicitly qualifying std::.... Not only that but it's bad practice in general and especially dangerous for beginners.
 
2:33 PM
Well, there are a few things: 1. Beginners also have to add the include files. They also don't know what 'int main' really means. It seems that the things that have to be added 'on top of the program' are less confusing than things that have to be added everywhere. Also, the beginners don't know that a program can consist of several files (until the chapter 'Libraries'), so that is not an issue.
2. It is imposible, at the beginning, to explain all the necessary parts of a beginner's C++ program. They just have to follow the instruction on certain things. I do hint about the meaning of those
In fact, I would remove 'using namespace std" after chapter "Libraries", so that they can get a lot of examples of that in the "23. Big integers" chapter. Chapter 24. is only informative, it does not have any real code.
 
The first 2 points are irrelevant to the problem of using namespace std;. 1) Yes, they wont know everything immediately. That doesn't mean that we should add things that they don't know because there are other things that they don't know. 2) Same point #1. 3) "They may forget it" is not an argument. They may forget "d" in "double", they may forget "using namespace std;", the may forget a semicolon. That's really irrelevant.
All you have to tell them is that std::cin is a name just like double or int. They won't know it's separate unless you tell them to. You tell them that :: is part of the name. Which is more true then you might think.
 
2:49 PM
@KevinC 1. that is irrelevant (the things not shown are fine. Assuming necessary includes is, well, necessary. Leaving out random bits from the function body that you /do/ show is a very different thing.)
2. so, just use qualified names
3. needs proof. Also, they may forget many other things. The rest of your rambling seems self-contradictory ("they won't understand" vs "they can spot [...] is separate").
There's no excuse for not being explicit about (using) namespace std. And, off-topic: if you don't link to fully working, self-contained sample that have the required includes, your sample suck.
 
Also #includes are orthogonal to namespaces. Not sure why you brought them up.
 
@Jefery I don't think it's true at all. But then again, if you write for people who can't spot when they mistype std::string as std:string then they're not fit for the course
@Jefery He means "there's more that I'm leaving out for brevity"
 
3:02 PM
"Also #includes are orthogonal to namespaces. Not sure why you brought them up."
- it was an example of other things that have to be added 'on top of the file', and not truly explaind in detail.
Ok, so I would say that this discussion is heading into a discussion on simplicity. Now, that is a problem. Simplicity is sometimes objective, but many times it is an subjective quality. I think one thing is 'simpler', you think the opposite. We can argue all day about what each of use considers 'simpler', but it is usually hard to convince the other side.
 
@sehe Fair enough
 
@KevinC The whole point is using namespace std; should not go on top of the file (ever) in samples
@KevinC Simplicity is not what's required when teaching C++
It is required, but please do not oversimplify the samples (because that's what students tend to copy)
@KevinC That's not a different argument. It's a repeat of several other occasions where you introduced the same argument.
My opinion is the same in the case of other authors
 
"That's not a different argument. It's a repeat of several other occasions where you introduced the same argument." - it was in another chatroom, I felt necessary to repeat it here.
"My opinion is the same in the case of other authors"
Ok, but still their books are listed in 'definitive' list. So, it seems that it is not such a crucial point. Otherwise, their books would be removed.
I was thinking: i could remove using directive from many programs but.. here is where I will run into problms:
I was thinking of adding 'using namespace std' into main() . But, after I introduce functions, I will still need the std prefix for vectors in function parameter list. So, that can't be a solution. This was a digression, but still I thought that I should mention it.
Can we conclude that using directive is not desirable anywhere, but in the books for beginners, in first parts of the book, it is not a crucial issue?
 
3:54 PM
@KevinC Again?
2 hours ago, by Kevin C
Ok, I can agree that using namespace std is a bad practice. But here is the issue: the book is for beginners. Some additional syntactic elements which might seem trivial to you and me are usually scary for beginners. So, it's not only my book that uses 'using namespace std'. For example, on 'definitive' list, the Stroustroup's book also (kind-of) does that, and the Eckel's book, too. So, if others are using it, I also took that liberty.
That's in this room.
 
It is not exactly the same statement as before, it is slightly changed.
 
Well blimey. That's too subtle for me.
@KevinC I agree that doing things right conflicts with the goal of brevity
 
Ok, dou you have any further arguments, and I would especially want an argument that refutes my 'not critical issue' point?
 
@KevinC Yeah it's not crucial
 
Then you agree?
 
3:59 PM
@KevinC It's not the only criterion. I was just participating in this discussion, not reviewing your work
Yet, you have an un-acclaimed web resource (that you're affiliated with) and we have no other thing to go on than our own scrutiny.
(In fact I think I was more like /rescueing/ the discussion; I'm happy that part seems to have succeeded)
 
Yes, but if it is a discussion, then it needs to be based on arguments. Your argument so far is 'I don't tolerate, in any examples, using directive at global scope". But that is not an argument, that is an opinion.
 
Fine, Kevin. I have given you my arguments. I've linked to the explanations why using namespace is risky (and you agreed, so we didn't elaborate). Don't make it "Just your opinion, man" now. Because like your "red-herring" accusations earlier is just complete bullocks.
So much for rescueing. We had a decent discussion on arguments, and you go full kamikaze once we reached a conclusion that's insatisfactory to you.
in Lounge<C++>, 16 hours ago, by Kevin C
@Jefery You must have the same criteria for all books. And, since mine is for beginners, that using namespace thing should be even less important. You can't make it an argument for excluding my book, as you have obviously included other books not meeting your criteria.
In the light of your real goal (your agenda is showing), how about we suggest adding an answer to this question that lists, informally, people's favourites that lack independent review/etc.? We could name it "Here be dragons" or "Read at your own risk".
 
@KevinC It's just terrible and it adds nothing.
 
Sehe, please, don't be that fast on accusation. Hear what I have to say. Don't jump to conclusions. We agreed that using directive is not desirable (in general). But I'm making a special case, and I'm arguing that this general rule does not apply in my special case. That is a valid argument.
For example, how many other things that are generally not recommended are present in beginners books? There are many things. It is because some oversimplifications are allowed when explaining things to beginners. So, that is what I have been saying, and you didn't yet put up any argument that defeats th
 
@KevinC It was you who did that. Twice now
 
4:12 PM
I did what? Where?
 
> I'm arguing that this general rule does not apply in my special case. That is a valid argument.
Not if I consider you argument bollocks
2
 
@KevinC Accuse
@Jefery That's an assumption and an opinion.
 
Yes
 
Where did I acuuse anyone here of anything?
 
@KevinC The red herrings and "not bringing any arguments."
I'm done here.
 
4:13 PM
That would be most impolite.
 
No, it's not actually an assumption. It's the truth. Trust me: I consider that argument bullshit.
 
I'm happy to be impolite. After spending way too much time on your behalf
 
@Jefery Ok 'consider' is an opinion, not an argument, right?
@sehe Now, that is rude!
 
I've explained my argument against using directives above
That was an argument
Yours are also opinions and not truths.
 
@Jefery Yes, but you also need to refute my special case. For example: you shouldn't walk ascross the street : true - but you can cross the street over on zebra.
 
4:15 PM
@KevinC Sorry. It won't happen again.
 
@KevinC I've discussed above that especially in your special case (teaching to beginners) that rule is true.
Especially in that case
 
@sehe Ok, thank you.
@Jefery Ok, I'm goind to reread it to see if I missed anything.
 
In fact I've only ever discussed your special case.
I don't think I ever explained why it's bad outside of your special case.
Thankfully there's a whole SO question regarding that
 
@Jefery Ok, let me go through you messages one by one. I was mostly concentrating on sehe's argument, and this talking to two people at once is slightly confusing.
 
2 hours ago, by Jefery
@KevinC I don't understand how using namespace std; is supposed to be more comforting then std::vector<int> for example.
Go from here ^
 
4:26 PM
"I don't understand how using namespace std; is supposed to be more comforting then std::vector<int> for example."
- 'comforting' is a subjective feeling. I don't know why is it comforting. But when talking to students I get a feeling that they like 'using namespace std' more. And, obviously, Stroustroup and Eckel have the same feeling.
I have to go AFK for a few mins
"Isn't it easier to explain that the name of a vector type is std::vector and that for all intense and purposes std::vector is the full name of said type (it's actually ::std::vector<T> but you get the point) as opposed to: "Oh yeah, we have to add using namespace std; in the top of the file"."
- this is a question/argument on simplicity, in a case where it isn't obvious what is simpler.
"But what is a namespace?" -- "Don't bother with it for now"
- the book actually hints about the answer when it says "the names are organized in namespaces". Also, don't tell me that you expect that any book should start with a big elaboration on namespaces. That would be quite unbelievable to me. When explaining to beginners, some things need to be oversimplified.
 
You can use > quote on a line to simulate quotes.
Like this:
> Quote
@KevinC Yes it is. So if your claim that you "feel" they like "using namespace std;" more. And the fact that Stroustroup and Eckel use it as opposed to the other 3 (or even more) that are recommended in the book list is not exactly comforting.
@KevinC I'm not sure what your reply here is. I'm arguing in favour of the simplicity of just saying that the name of the type is std::vector as opposed to "Put using namespace std; only in these cases.
@KevinC I never said I expect an introduction with namespaces. In fact I've claimed that not even mentioning them is a better idea (by using std:: prefix for the type names as opposed to actually naming namespace in the code everywhere I need).
The last one in particular sounds like a strawman.
 
4:49 PM
> " In fact I've claimed that not even mentioning them is a better idea
Ok, right, that part argument of mine is then not valid. So, you vouch for not introducing the concept of namespaces with the price of necessitating a slightly more cubersome syntax.
I'll try to find instructions on those quotes...
 
@KevinC Syntax is not a problem.
@KevinC It's "Markdown".
 
YOu must be joking?
 
Which also allows *abc* to be abc and **abc** to be abc
And `code` to be code
@KevinC I'm not.
Typing 5 characters per type is not a problem.
 
Ok, I have to go AFK.. but anyway, interesting opinion. Isn't that opinion rare?
 
Not in the C++ community I don't think.
 
4:59 PM
If you have using namespace std; then you can't name your function (for example) list, distance, or sort without a confusing error message
 
5:09 PM
Compiles without problem:
#include <iostream>
using namespace std;
int list(int a, int b) { return a+b; }
int main()
{ int c = list(3,4); }
 
5:20 PM
Ok, that "syntax is not a problem" is an opinion, but I would like to have a short discussion about it. I also think that, in many cases, syntax is not a problem. But there is a line, a limit there. I mean the extreme would be something like the 'obfuscated c contest', and you can't send beginners to compete there.
Now, I would also like to mention that C++ is probably the language with the most complicated syntax of all commonly used languages. That is due to its history. So, if the C++ community thinks that syntax ins not a problem, I must say that there is a question of bias.
 
@KevinC I'm talking in the context of using namespace qualifications.
Of course obfuscated syntax is a problem.
 
You are just drawing a different limit compared to mine, nothing else, and, in fact, those two lines are not that far apart, at least not for you and me. But, perhaps, for beginners, they are far apart.
 
@KevinC well, I remember a dozen questions on SO that were direct result of the person writing using namespace std; and declaring a function with the name that was the same as the function declared in std namespace. I'll let you know when I find them
 
@KevinC "drawing a different limit"? What do you mean? Also what two lines?
I'm saying that using std::vector<int> as opposed to vector<int> is not really a problem.
 
The line that separates compilacted syntax from simple syntax.
 
5:28 PM
Sure, but it's not relevant here. In the context of namespaces (especially in the context of only 1 level deep namespaces) I don't think that the two syntaxes std::vector<int> and vector<int> are much different in terms of readability and writability.
As I said if for someone writing 5 more characters is a problem, then you don't really want to deal with these people. IMHO.
Also yes, I'm stating opinions and trying to explain them. Just like you are. It's not like anyone here is trying to present facts.
 
Of course, there are a lot of opinions involved.
> As I said if for someone writing 5 more characters is a problem, then you don't really want to deal with these people. IMHO.
Ok, I beg to differ there. In fact, I would argue that (in my experience) 99% of beginners do mind the syntax a lot. Your criteria would (IMHO) probably exclude most of today's professional programmers (looking at the time when they were beginners). Could I also add that Python community seems to be much more considerate towards beginners. And perhaps, the C++ community is truly hostile towards beginners, and perhaps
 
5:51 PM
Ok, so I still think that this whole argument boils down to the question on simplicity. I don't know what more to add, except to repeat that it is subjective (which doesn't mean that the issue is to be ignored). Butt I will think some more about the whole thing.

So, I propose, for the time being, that we skip the issue on using directive. Are there any more issues? Like 'double' vs 'int', is it an issue also, or should I disregard that?
 
6:19 PM
Oh yes, I forgot to reply to this one. I'll try the quote again:

Jefrey said:
> I'm not sure what your reply here is. I'm arguing in favour of the simplicity of just saying that the name of the type is std::vector as opposed to "Put using namespace std; only in these cases.

You see, exactly there: **you are arguing in the favor of simplicity** .But, in this case, "simplicity" is subjective. So, you are just saying "I think this is simpler". But that is your SUBJECTIVE feeling. Everyone is arguing in favor of their own perception of simplicity!
 
 
1 hour later…
7:46 PM
Mileniumbug said:
" well, I remember a dozen questions on SO that were direct result of the person writing using namespace std; and declaring a function with the name that was the same as the function declared in std namespace"

Ok, but aren't there 450 000 total questions on C++ on SO? A small number of problems is actually an excellent result.
 
 
2 hours later…
9:57 PM
Ok, does anyone else have an opinion on the book or on the discussion here? I would certainly like to hear it.
 
10:15 PM
@KevinC Yeah, the C++ community is "angry" at beginners because C++ is not a beginner language IMHO.
Which is what I claimed yesterday too.
@KevinC Using double as opposed to int makes little sense to me.
Floating point arithmetic is very weird. Not sure I'd like beginners to deal with that.
Division is just something you have to mention for int. It's really the only thing that is perhaps weird.
 
I'll rehash the argument of Robot: in my school, the integer division was introduced earlier than real division
 
@KevinC Yes. There's no objective solution here. We all try to explain out own opinion.
 
About C++ for beginners: Well, yes, I remember. Well, you certainly have a right to have that opinion, in my view. Especially considering many other books and teaching materials that I have stumbled upon, I would even say that, given the curent situation, that opinion is more justified than not.
But, you see, in my case, I am expecting to have trouble in reacing an agreement with you. I mean, I have written a book that aims to prove the exact opposite of what you are saying. Of course, I have no 'proof' that I am correct, only time can tell. But also, I think it all has nothing to do with p
@milleniumbug Yes, mileniumbug, that is true. Integer division is explained earlier because children, at that time, do not yet know about real numbers and fractions. But, once fractions and real numbers are explained, the 'real division' becomes more natural, and most people forget about integer division.
 
also integer division is more useful in general
 
@milleniumbug Maybe in computer world integer division is more usefull. But, the book explains integer division, too, in a lot of detail, just a bit later.
 
10:29 PM
I very hope it does
 
@orlp Do you have anything to add?
 
not particularly interested
sorry
 
@orlp ok, fair.
 
to be fair I'm not too keen on discussion now too. Maybe tomorrow or the day after it
 
@milleniumbug That is OK.
 
10:52 PM
So, this discussion is opened again for new arguments and new opinions.
Particularly, I would like to know how many people here think that C++ is (or is not) appropriate for total programming beginners. My stance is that it is most appropriate.
------------
Also note that the 'definitive C++ book list' contains a section with books for total beginners, so that could be an argument that there are many people who think C++ is appropriate for beginners. This claim also seems to be supported by titles of many C++ books.
 

  last day (15 days later) »