To become a good C programmer (2011)
81–90 of 106 posts
Re: To become a good C programmer (2011)
#82Earlier quoted context omitted.
Even "i" can be changed to "index". My rule of thumb is this: If you wouldn't use the abbreviation when speaking, don't use it when coding. I don't understand why 'i' has been given a pass. The argument boils down to saved keystrokes. Typing is not the bottleneck.
> I don't understand why 'i' has been given a pass. The reason is that in FORTRAN variables starting with i, j, k..n were defined as integers. Back in the day I learned fortran first, then basic. People that learned basic first often would use the letter 'a' as a loop index instead of 'i' Now days I still use 'i' but often use indx instead because my editor doesn't highlight single letter variables easily.
Re: To become a good C programmer (2011)
#83Earlier quoted context omitted.
I think the style should be avoided; code shouldn't be compact and variable names should be descriptive. Artificial example: for( int i = 0 ; i should be: for( int count = 0 ; count It may be allowed to use i in place of count here, but this is the only place where single name variables should be permitted and only if i is really just a simple array index iterator.
There should always be a balance between brevity and being too verbose. all single letters = bad, java style thisIsALoopCounter = bad. and in the c world i is almost universally understood to be used as a loop counter and index. If I came across 'count' in a c code I (briefly) might think it was related to a count of items in an array or similar.
Re: To become a good C programmer (2011)
#84The more I learn C the more I hate it. At first it seems simple and easy but reading "Expert C Programming" is reading a laundry list of what's really messed up with the language. 80% of the problems would be solved by some sane syntactic sugar that compiles down to C
Re: To become a good C programmer (2011)
#85Earlier quoted context omitted.
4. Assemble 5. Load into assembly debugger 6. Learn There is "C", the language, which can be relatively simple. Or hopelessly opaque depending on the author. I think of C the language as just a shorthand for assembly. Only because that's how I use it. http://www.lysator.liu.se/c/bwk-tutor.html But then there is "C" in practice: the specifications, the "standard" libraries, preprocessors, Makefiles, autoconf, etc.
But what would qualify as an "asm code generator" if not a compiler? There are other free compilers. Clang comes to mind.
Re: To become a good C programmer (2011)
#86What's a good practical but small enough project you can do with C? Typically if you are learning Ruby or Node, people recommend creating a blog. What's something like that for C?
You could make a small game with SDL, perhaps?
Case in point: Star Control 2, a commercial title with a cult following, which had subsequently been open sourced, then modified to use SDL. Still works all the way from Windows through mobile phones to Solaris, thanks to portable C and the SDL library, and is an excellent game to boot. Original ran on DOS and the 3DO gaming console.
Re: To become a good C programmer (2011)
#87Earlier quoted context omitted.
Even "i" can be changed to "index". My rule of thumb is this: If you wouldn't use the abbreviation when speaking, don't use it when coding. I don't understand why 'i' has been given a pass. The argument boils down to saved keystrokes. Typing is not the bottleneck.
When I started to program in C I used "n" for the longest time, simple because it was quicker on to type on my first computer; "Next N" was a quick two taps on the N key. Guess the platform :-)
Re: To become a good C programmer (2011)
#88Earlier quoted context omitted.
Even "i" can be changed to "index". My rule of thumb is this: If you wouldn't use the abbreviation when speaking, don't use it when coding. I don't understand why 'i' has been given a pass. The argument boils down to saved keystrokes. Typing is not the bottleneck.
> I don't understand why 'i' has been given a pass. Because it is well enough established (in both programming and mathematics) that it communicates literally no less information to the reader than "iterator" or "index" would in the same context. > The argument boils down to saved keystrokes. Not at all. I, for one, find it easier to see the shape of the whole expression when the variable names are shorter.
Re: To become a good C programmer (2011)
#89Earlier quoted context omitted.
I hope you don't have a stroke: https://github.com/jsoftware/jsource/blob/master/jsrc/cip.c ...just one of the many source files that make the interpreter for the J language.
The 'style' even leaked out to file naming: a.c, ab.c, af.c, am.c, c.c, ca.c, cc.c, cd.c, cf.c, ... Brilliant! I doubt that this is either serious (unobfuscated) or handwritten code though.
Re: To become a good C programmer (2011)
#90Earlier quoted context omitted.
But what would qualify as an "asm code generator" if not a compiler? There are other free compilers. Clang comes to mind.
Let us see... in my day, we called an "asm code generator" an assembler... anyone remember MasterSEKA, Devpac, TRASH'M-One and ASM-one?
1. Program that reads some input (e.g., C language) and generates asm and/or opcodes.
2. Program that reads asm and/or opcodes and generates binary numbers ("object files").
No. 1 is what I need.
No. 2 is what I call an "assembler". Although terminology means less to me than what a program actually does.