|
-
September 24th, 2003, 11:56 AM
#8
Senior Member
Slarty no offense but half of the argument in that link you gave is that people new to the language won't know the syntax.
Just because it's not in straightforward english so that anyone can read it doesn't mean it's a bad thing, using shorthand can speed up the time it takes to code things because you don't have to spell out long words all the time, and on top of that most of the shorthand used makes reasonable sense on its own.
The point on the pre-processor is true however, but I've never had to define variables with it, I really don't see the point. If you need to define a variable then use the if built into the pre-processor, define should only be used for setting things that control code alteration like what OS the code is compiled on, etc...
The assignment syntax is fine, sure the == part can cause grief at first but the concept isn't that hard to wrap your head around, most people I know never considered it a problem when they were learning. As for x = y = 456, the assignment operator works from the far right first and assigns to the left, that simple, there's no tricks to it.
The ternary "?" operator is very useful for adding conditionals in places where you just need a quick if/else and are only returning variables based on it. One of the handiest places to use this is when formatting text for output, you can put it right in the output statement.
For loops are no good? Maybe the author should look at their code, because he messed up the while loop that "emulates" a for loop, the i++; should be at the end of the loop so that it increments in the right place. A for loop keeps the incrementing and initialization in a common place making it easier for a newbie to see what the loop is doing, the 0 to whatever is just something that you get used to, many compilers count 0 as the first number, learn it and get over it.
The fact that anything can be used as boolean is extremely handy, sure without proper naming it gets confusing but otherwise it makes checking things nice and simple.
I will agree with the strings though, c was awful for strings, c++ is a big improvement in that area, while there are still places where it could be better.
Pointer arithmetic is fairly straightforward, if you pass the memory location of a character to the character formatter in printf it prints that character, to the string formatter, it prints from that memory location until it finds the null. the memory for a single variable is sequential, it doesn't got 0,3,2,6,1,4,5 it goes 0,1,2,3,4,5,6 so referencing the 3rd character in the variable is a simple task of adding the appropriate number to the pointer, ie memory address, or using the variable as an array which does that for you.
Multidimensional arrays... I seem to recal using them in c, and c++.. sure they're limited by size constraints which is a pain but that's where vectors come in in c++... Yes I'll admit I like c++ much more than c simply if simply for the stl and streams.
Typdefinition makes for easier readability in most cases, I really don't see what the authors problem with it is...
Default scope is global? I seem to recall that if you define a variable in a function it lived and died in that function but never left it. If the author ment that it was global if defined outside any functions in the code then yes.. that would usually be where you declare global variables. And while static isn't the best keyword they could have used it's not all that out of the blue.
Modules take some getting used to but would you rather read a file that's 3,000,000 lines long or have many little files that you can read over and see what it's doing without getting lost in the code? This makes it easier to read and modify.
I do agree with the printf being error prone.
While there is truth to some of what you say, a lot of it isn't all that accurate, you leave out why the "feature" was put there in the first place. C is not by far the best language out there but it's small and easy to write little programs with little code, something Java makes a chore out of, and it's fast.
As for the pre-processor tutorial, to get back on track, I think it'd be a great idea. But when you write it keep in mind the problem that Slarty pointed out, #DEFINE shouldn't be used to declare variables in most cases and if it is you should put brackets, "()", around the definition to keep the order of operations intact. If you purposely need to have the side effect that Slarty mentioned happened then chances are you don't need that tutorial.
Reality is the one who has it wrong, not you
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|