News for hackers. Stuff that matters.
Re:John Carmack on Inlined Code by idlewords on Friday September 26, 2014 @04:47PM (#8374763)
I would enjoy reading more comments from people who have been programming for a very long time about how their coding style has changed.
Re:John Carmack on Inlined Code by abecedarius on Friday September 26, 2014 @06:22PM (#8375215)
I don't have much to say that'd fit in a comment, but for science here are two of my programs in C doing similar tasks, one from the late 1980s, one from 2008: https://github.com/darius/req https://github.com/darius/vicissicalc
Re:John Carmack on Inlined Code by EddSeabrook on Friday September 26, 2014 @08:55PM (#8375651)
Line 457-470 of vicissicalc.c: why do you use else if here rather than switch-case?
Re:John Carmack on Inlined Code by ufo on Saturday September 27, 2014 @12:07AM (#8376050)
Might have been because of the `else if (ch == 'q') break;` line. If he used a switch statement he would have needed to use a goto to break out of the loop.
Re:John Carmack on Inlined Code by abecedarius on Saturday September 27, 2014 @12:27AM (#8376079)
That's a reasonable guess, but a return would work there. I think I did it this way because all the breaks you need in a switch are noisy -- too noisy if you'd like to write one action per line. However, you can mute the noise by lining it up:

        switch (getchar ()) {
            break; case ' ': enter_text ();
            break; case 'f': view = formulas;
            break; case 'h': col = (col == 0 ? 0 : col-1);
which also makes oops-I-forgot-the-break hard to miss. I hadn't thought of that pattern yet. (You could define a macro for "break; case" too; my friend Kragen calls that IF.)

But I mostly stopped coding in C after around this time.

Re:John Carmack on Inlined Code by kragen on Sunday September 28, 2014 @04:02AM (#8379213)
I thought you were the one who suggested the IF and ELSE macros in http://canonical.org/~kragen/sw/aspmisc/actor.c. :)

Interestingly, in http://canonical.org/~kragen/sw/dev3/paperalgo, I haven't yet run into the desire to have more than one `case` in a pattern-matching `switch`. I just added that piece of code from Vicissicalc to the paperalgo page.

Re:John Carmack on Inlined Code by e12e on Saturday September 27, 2014 @01:57AM (#8376209)
The first break is ignored?
Re:John Carmack on Inlined Code by dlp211 on Saturday September 27, 2014 @02:37AM (#8376276)
Not exactly. But it does create a no-op default. I've never seen/used this pattern, so I would have to go compile this down into assembly and play with it to give you a more complete answer.
Re:John Carmack on Inlined Code by abecedarius on Saturday September 27, 2014 @04:48AM (#8376495)
Dropped by dead-code elimination. A compiler might conceivably issue a warning that the first break is unreachable, though that's never happened so far.
Re:John Carmack on Inlined Code by krylon on Friday September 26, 2014 @06:33PM (#8375256)
Thank you very much!
Re:John Carmack on Inlined Code by tgb on Friday September 26, 2014 @05:22PM (#8374957)
Seconded! Also I would like to see comments on how programming styles in general have changed over the years - does a 80's era high-quality program still look like a 2010's high-quality program once you factor out the syntactic sugar?
Re:John Carmack on Inlined Code by at-fates-hands on Friday September 26, 2014 @07:07PM (#8375361)
I find it fascinating that larger traditional languages have changed little over time, while the languages of front-end development seems to change daily.

My coding style seemingly morphs about every few months now. It's sad to think stuff I wrote even three years ago I would never show someone interviewing me or put it in a portfolio nowadays.

Re:John Carmack on Inlined Code by GFK_of_xmaspast on Friday September 26, 2014 @10:05PM (#8375804)
If you don't hate the code you wrote six months ago you're stagnating.
Re:John Carmack on Inlined Code by acdha on Saturday September 27, 2014 @11:55AM (#8377335)
This should only be true during the early days of your career. If you're out of the novice stage, you shouldn't be writing hateful code – maybe there's a new library to use or something you now understand about the problem but that's hardly the level of hatred.
Re:John Carmack on Inlined Code by hisham_hm on Friday September 26, 2014 @06:46PM (#8375288)
For this purpose, it might be worth checking out some classic books such as "Software Tools" and "Project Oberon".