- WebPositive matures
- Lesson 10: More Pointers and the Command Line
- My Interview About Haiku and BeOS on omnes.tv
- Whole Lotta Lessons Goin' On
- My Impressions from SCaLE 2010
- WebPositive emerges
- Lesson 7: Losing My Memory
- Diving into WebKit
- Lesson 6: More Loops and Conditions
- Lesson 5: Arrays, Strings, and Pointers
Programming Lesson 3
Continued (mis)adventures in programming for all of the curious into the insights of being a codemonkey. In this lesson, we examine the different types of data we can use, a more in-depth look at how to print to the screen, and more! Learning to Program With Haiku, Lesson 3.pdf All previous lessons have received some minor revisions and code is now colored for better readability.
- darkwyrm's blog
- Login or register to post comments







Comments
Re: Programming Lesson 3
Nice one, DarkWyrm!
Was the printf line in bughunt#2 intentionally the same as in the hypotenuse example or is that a copy&paste mishap?
You may want to explain the difference and use of declarations and definitions a bit.
Maybe you should keep one page with an index of all lessons that you can link to in every episode.
Keep it up!
Regards,
Humdinger
Re: Programming Lesson 3
That would be a copy and paste error, which I just fixed. Thanks for pointing it out! :-)
Re: Programming Lesson 3
Hi,
Some wording with regards to explaining operators is incorrect and misleading. When using "a++", a is not incremented after the whole expression, but after taking the value of a and inserting it into the expression. This can be illustrated:
int a = 1;
int b = a++ + a++;
What you say makes it sound as though b will be evaluated to 2, but it will be 3.
Some more things to point out:
* Don't teach beginners bad style like "int a, b;". Always declare variables on separate lines for easier reading later on.
* In C++, don't put "void" into functions that don't take arguments, it's superfluous.
* Why not mention some Haiku specific types, like "uint8"?
Otherwise, thanks for doing these lessions!
Re: Programming Lesson 3
Count me as confused, then. Could you then explain this to me?
#include
int main(void)
{
int a = 1;
int b = a++ * a++;
printf("a is %d, b is %d\n",a,b);
return 0;
}
Output is as follows:
$ ./foo
a is 3, b is 1
When I flip it around and do ++a * ++a, I get what would be expected, based on your explanation -- a is printed as 3, but b is 9.
Re: Programming Lesson 3
Wow, maybe it's a good thing that you are doing these lessons and not me! :-)
Re: Programming Lesson 3
AFAIK evaluating things like f(a++,a++) is ambiguous. Evaluation order and results are undefined and completely compiler dependent.
Nice explanation on it: http://c-faq.com/expr/evalorder2.html
P.S.
Lessons are fine. I am waiting for something Haiku-specific, it should be interesting.
Re: Programming Lesson 3
Good work, I will recommend to my colleagues beginners in programming. As someone already pointed out, the syntax is easy to learn in web; practical examples with your pleasant way of writing and explain would be incredible.
It's good for Haiku community too as well, since many people can born here.
Re: Programming Lesson 3
Haiku-specific is coming. I'm starting with the basics that you would see in C. Once I get into the object-oriented concepts in C++, expect to see stuff that is geared toward the BeOS API in general. Rest assured, though, that I won't leave out Haiku-specific features like the layout management code.
PS Thanks for the note about evaluation. Much appreciated. :)