You have indeed made your point, and quite well.

Edit: What about the Python version?


Code:
print "Hello World"
elfprince13 wrote:
Your first C program:

Code:

#include <stdio.h>

main()
{
    printf("Hello World\n");
}

Questions it raises:
What is stdio.h? "Standard libraries for input and output."
What is that \n thing? "It makes a newline"


Have I made my point?


No, because that main isn't valid. You're missing the return type of int as well as the return. It may be valid in old, not-used-by-anyone C, but if you're teaching someone that you're already off to a terrible start.

But I didn't say there wasn't less boilerplate in C than Java, so you're countering a point I didn't try making. I just said C has quite a bit of boilerplate as well - which is true. HelloWorld has less, yes, but as soon as you get even slightly more complicated the boilerplate builds up quickly.

As Kerm kind of pointed out, there are better languages to start with - like Python. No boilerplate, no tricky memory management, no pointers, tons of growth potential, etc... C really is not a good starting language, and neither is Java.
Is the complexity of a "Hello World" program any way to judge the usefulness or complexity of a programming language? It may provide a slight hint at the the complexity, but it also may be misleading, depending on the purpose of the language.
seana11 wrote:
Is the complexity of a "Hello World" program any way to judge the usefulness or complexity of a programming language? It may provide a slight hint at the the complexity, but it also may be misleading, depending on the purpose of the language.


Of course not, but how much boilerplate and crap is involved IS a roadblock to getting someone started. Explaining Python's "Hello World" is a piece of cake and easily understood by just about anyone. Explaining Java's is ridiculous and requires a lot of Java-specific knowledge to have any hope of understanding.
Kllrnohj wrote:
No, because that main isn't valid. You're missing the return type of int as well as the return. It may be valid in old, not-used-by-anyone C, but if you're teaching someone that you're already off to a terrible start.

So explain return types. You still don't have to get into all sorts of arcane inheritance rules and OOP-theoretical nonsense which won't make sense to someone who doesn't know how to program yet. You can concretely demonstrate the purpose of a return type in the main method in C, since you don't have to explain "void" to someone who doesn't know what return types are yet. Instead you can show how the int you return from main is the program's exit status code that it hands back to the execution environment.

Quote:
I just said C has quite a bit of boilerplate as well - which is true. HelloWorld has less, yes, but as soon as you get even slightly more complicated the boilerplate builds up quickly.

Once you get into programs where you need to compile multiple source files, sure, but I can't think of any instances where that is necessary (or even desirable) for the sorts of assignments that are given to intro students. Instead the boilerplate appears gradually, and, for the most part, in places where it has a real use that can be demonstrated and explained concretely.

Quote:
As Kerm kind of pointed out, there are better languages to start with - like Python. No boilerplate, no tricky memory management, no pointers, tons of growth potential, etc... C really is not a good starting language, and neither is Java.

I agree that Python is a fantastic starting language, and the reason I brought up C at all is because I think C does just fine as a beginners language and it seemed absurd that someone would be upset with Python by comparison.

Kllrnohj wrote:
Explaining Python's "Hello World" is a piece of cake and easily understood by just about anyone. Explaining Java's is ridiculous and requires a lot of Java-specific knowledge to have any hope of understanding.

QFT.

And for the record, a proper "Hello World" Python program should be


Code:

import sys

def main():
    print "Hello World"
    return 0

if __name__ == "__main__":
    status = main()
    sys.exit(status)


I probably wouldn't teach that either, but since we've decided that the purpose of a first program is to be as correct as possible, rather than as understandable as possible...
elfprince13 wrote:
And for the record, a proper "Hello World" Python program should be


Code:

import sys

def main():
    print "Hello World"
    return 0

if __name__ == "__main__":
    status = main()
    sys.exit(status)


I probably wouldn't teach that either, but since we've decided that the purpose of a first program is to be as correct as possible, rather than as understandable as possible...


Uh, no, that is definitely not a proper hello world program. That is intentionally verbose for absolutely no reason whatsoever.

"proper" hello world in that you can't run it by importing it would just be:


Code:
def main():
    print "hello world"

if __name__ == '__main__':
    main()


Everything extra you had did not increase its "properness" at all. Quite the opposite, I would argue what you have is significantly *LESS* correct as what you actually did is port C, not write Python. Moreover, just "print 'hello world'" fully qualifies as proper, it just has a different meaning than the idiomatic "__name__ == '__main__'" approach.
Kllrnohj wrote:

Everything extra you had did not increase its "properness" at all. Quite the opposite, I would argue what you have is significantly *LESS* correct as what you actually did is port C, not write Python.

So what you're saying is that relying on the C compiler to automatically generate an exit status of 0 is bad behavior, but relying on the Python interpreter to do the same is not?
elfprince13 wrote:
So what you're saying is that relying on the C compiler to automatically generate an exit status of 0 is bad behavior, but relying on the Python interpreter to do the same is not?


Nope. Using the incredibly terrible "feature" that for main and main only you can omit the return type and return statement is a horrendously bad way to intro someone to programming. You should never start off with a rarely used and not widely known compiler trick. It will cause some to get the idea that main is somehow special and not just yet another function.

EDIT: Oh, and let's not forget python doesn't generate an exit status of 0, but it instead uses EXIT_SUCCESS. Just doing an implicit "return 0" is actually wrong - return values for main are not defined. 0 on some platforms could be an error.
Kllrnohj wrote:

Nope. Using the incredibly terrible "feature" that for main and main only you can omit the return type and return statement is a horrendously bad way to intro someone to programming.

No, I probably shouldn't have omitted the return type, but omitting returning the status code is common practice in every language I've ever used.

Quote:
It will cause some to get the idea that main is somehow special and not just yet another function.

To the compiler/linker, it is special (in platform dependent ways). You really ought to read this: http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html

And even though I don't want to teach anyone C++ as a first language, I also don't want to teach people to use features of C that are incompatible with C++, where main is defined with special properties as a standard. If they're ever going to learn C++ they should begin to think main is special right off the bat: an implicit "return 0;" at the end of main is required by the C++ standard, and, unlike in C, C++ forbids main from being called recursively.
elfprince13 wrote:
No, I probably shouldn't have omitted the return type, but omitting the return is common practice.


Not really. I've yet to come across really any sample or program that omits the return in main. It's very uncommon.

Quote:
To the compiler, it is special (in platform dependent ways). You really ought to read this: http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html


It really isn't special other than that by convention the compiler assumes your entry *function* is called main. It's still just a function - to the developer as well as the compiler.

And don't forget, on a very widely used platform (that being Windows, of course) it isn't necessarily main at all, but wmain or _tmain.

Quote:
And even though I don't want to teach anyone C++ as a first language, I also don't want to teach people to use features of C that are incompatible with C++, where main is defined with special properties as a standard. If they're ever going to learn C++ they should begin to think main is special right off the bat: an implicit "return 0;" at the end of main is required by the C++ standard, and, unlike in C, C++ forbids main from being called recursively.


It may be legal in C and C++, but it's still special to main - and in this case that shouldn't be taught at all much less right out the gate.

Oh, and you can *totally* call main recursively on some compilers. It is not forbidden at all. Instead, it is basically defined as being undefined. So calling main recursively isn't portable, but on VC++ and G++ it works just fine. Which makes sense, of course, because main is just a function, same as any other.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 2 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement