0844: "Good Code"

This forum is for the individual discussion thread that goes with each new comic.

Moderators: Moderators General, Prelates, Magistrates

User avatar
LucasBrown
Posts: 299
Joined: Thu Apr 15, 2010 2:57 am UTC
Location: Poway, CA

0844: "Good Code"

Postby LucasBrown » Fri Jan 07, 2011 5:00 am UTC

Image
Alt text: "You can either hang out in the Android Loop or the HURD loop."

To quote somebody's signature:

Code: Select all

Good Code                                                                                            Fun Code
Readable, Understandable, Maintainable, Self-Explanatory, Idiomatic, Efficient, Optimized, Elegant, Hackvalue

User avatar
ysth
Posts: 183
Joined: Wed Apr 11, 2007 7:21 pm UTC

Re: 0844: "Good Code"

Postby ysth » Fri Jan 07, 2011 5:06 am UTC

Awesome hovertext.
A math joke: r = | |csc(θ)|+|sec(θ)| |-| |csc(θ)|-|sec(θ)| |

Hypoon
Posts: 9
Joined: Wed Oct 27, 2010 5:25 am UTC

Re: 0844: "Good Code"

Postby Hypoon » Fri Jan 07, 2011 5:08 am UTC

Of course, there's always the alternative: adjust the requirements to fit the existing (already working) code ;-)
Unfortunately, it's not as profitable as some would like...

User avatar
Bonooru1234
Posts: 12
Joined: Fri Oct 15, 2010 12:21 am UTC

Re: 0844: "Good Code"

Postby Bonooru1234 » Fri Jan 07, 2011 5:11 am UTC

what are HURD and Android loops?

User avatar
Linux0s
Posts: 247
Joined: Sat Dec 29, 2007 7:34 pm UTC

Re: 0844: "Good Code"

Postby Linux0s » Fri Jan 07, 2011 5:11 am UTC

Or just play Angry Birds:

http://abstrusegoose.com/331
If the male mind truly were a machine it would consist of a shaft and a bushing.

User avatar
just john
Posts: 61
Joined: Thu Nov 08, 2007 2:11 pm UTC
Location: Poughkeepsie, NY
Contact:

Re: 0844: "Good Code"

Postby just john » Fri Jan 07, 2011 5:13 am UTC

The lesson: To achieve good code, you must collect underpants.
* Radio Free Entropy: http://just-john.com/jjMusic

Radical Pi
Posts: 17
Joined: Tue Jul 21, 2009 1:32 am UTC

Re: 0844: "Good Code"

Postby Radical Pi » Fri Jan 07, 2011 5:14 am UTC

I have now decided that all people on my FRC Robotics team must read this comic before requesting any programming done. This is a PERFECT depiction of what happened last year (3.5 weeks on "Right", 3 days on "Fast", 3 months later we made it to "Good Code"). GET OUT OF MY HEAD RANDALL!

Hypoon
Posts: 9
Joined: Wed Oct 27, 2010 5:25 am UTC

Re: 0844: "Good Code"

Postby Hypoon » Fri Jan 07, 2011 5:17 am UTC

Bonooru1234 wrote:what are HURD and Android loops?

I could be wrong, but I think it's safe to say he's referring to the GNU/Hurd and Google's Android projects, specifically indicating that they represent examples of the two loops (taking forever to fix messy code vs. taking forever to write good code).
Last edited by Hypoon on Fri Jan 07, 2011 5:20 am UTC, edited 1 time in total.

lw7av
Posts: 1
Joined: Mon May 31, 2010 7:08 am UTC

Re: 0844: "Good Code"

Postby lw7av » Fri Jan 07, 2011 5:19 am UTC

Looking at the Hurd loop (Do things right), I associate it more with Duke Nukem Forever than with Gnu Hurd

User avatar
coreytabaka
Posts: 2
Joined: Fri Jan 07, 2011 5:21 am UTC
Location: Silicon Valley

Re: 0844: "Good Code"

Postby coreytabaka » Fri Jan 07, 2011 5:27 am UTC

Android is in the do things fast loop, as much as the Android team may try to keep it in the do things right loop. Chip vendors and handset manufacturers are a constant push toward fast side of the force.

User avatar
Me321
Posts: 164
Joined: Fri Oct 09, 2009 4:03 am UTC

Re: 0844: "Good Code"

Postby Me321 » Fri Jan 07, 2011 5:50 am UTC


++$_
Mo' Money
Posts: 2370
Joined: Thu Nov 01, 2007 4:06 am UTC

Re: 0844: "Good Code"

Postby ++$_ » Fri Jan 07, 2011 6:22 am UTC

I feel so sorry for the little "Good Code" box. It must be so lonely down there :(

rpgamer
Posts: 109
Joined: Thu Oct 01, 2009 3:54 am UTC

Re: 0844: "Good Code"

Postby rpgamer » Fri Jan 07, 2011 6:24 am UTC

I'd wager alcohol is a necessary step on the mysterious path to good code.
All it takes is one bad day to reduce the sanest man alive to lunacy. That's how far the world is from where I am. Just one bad day.

Kobukson
Posts: 5
Joined: Fri Nov 06, 2009 2:28 pm UTC

Re: 0844: "Good Code"

Postby Kobukson » Fri Jan 07, 2011 6:30 am UTC

This would make a nice print to go next to the old Tech Support Flowchart ^^

smartalco
Posts: 44
Joined: Wed Jul 23, 2008 4:41 am UTC

Re: 0844: "Good Code"

Postby smartalco » Fri Jan 07, 2011 6:35 am UTC

rpgamer wrote:I'd wager alcohol is a necessary step on the mysterious path to good code.


http://xkcd.com/323/ ?

Lewton
Posts: 121
Joined: Tue Apr 08, 2008 9:15 am UTC

Re: 0844: "Good Code"

Postby Lewton » Fri Jan 07, 2011 7:28 am UTC

There's no such thing as good code
only good enough

Abyss123
Posts: 1
Joined: Fri Jan 07, 2011 7:36 am UTC

Re: 0844: "Good Code"

Postby Abyss123 » Fri Jan 07, 2011 7:41 am UTC

???

PROFIT

User avatar
A_of_s_t
Posts: 180
Joined: Tue Aug 26, 2008 5:10 am UTC
Contact:

Re: 0844: "Good Code"

Postby A_of_s_t » Fri Jan 07, 2011 7:44 am UTC

Story of my life.
Check out my web interzones powered by Web 3.0 technology running on Mozzarella Foxfire:
Spoiler:
Image
Image
Image

User avatar
CorruptUser
Posts: 10546
Joined: Fri Nov 06, 2009 10:12 pm UTC

Re: 0844: "Good Code"

Postby CorruptUser » Fri Jan 07, 2011 7:47 am UTC

Hypoon wrote:Of course, there's always the alternative: adjust the requirements to fit the existing (already working) code ;-)


Good luck with that, what with tax laws changing on a monthly basis. Accounting makes up a not-insignificant chunk of the programming world, to say nothing of the other parts of the business world. Most businesses have changing demands, whether it's through regulation or their own desires. Trying to reason with you customers will inevitably sound like you are just stalling, and may cause them to look elsewhere.

Video game developers are constantly changing their requirements, often because of the demand. Look at how fast games changed from 1990 to 2000. You went from Wolfenstein 3D to Half-Life 1. Actually, that was 1992 and 1998 respectively, just 6 years. Every time a competitor adds something new to a game, you often want to incorporate that into your own engine, etc. For example, in Supreme Commander, you zoomed in on your mouse pointer, rather than the center of the screen. It's a nice addition at first, but after getting used to it, you feel frustrated playing another RTS without it. It's like playing Dune II and finding out you can only select 1 unit at a time.

Amberfire287
Posts: 5
Joined: Wed Dec 08, 2010 12:12 am UTC
Location: Melbourne, Australia.

Re: 0844: "Good Code"

Postby Amberfire287 » Fri Jan 07, 2011 8:16 am UTC

Knowing nothing about coding, I find that the best application of this comic to my life is through cleaning my room/house. :?

User avatar
Negated
Posts: 230
Joined: Wed Jan 13, 2010 6:31 am UTC

Re: 0844: "Good Code"

Postby Negated » Fri Jan 07, 2011 8:21 am UTC

You need goto to get to good code.

User avatar
cephalopod9
Posts: 2030
Joined: Sat Dec 02, 2006 7:23 am UTC

Re: 0844: "Good Code"

Postby cephalopod9 » Fri Jan 07, 2011 8:48 am UTC

smartalco wrote:
rpgamer wrote:I'd wager alcohol is a necessary step on the mysterious path to good code.


http://xkcd.com/323/ ?

Go up, not north.

This is extremely informative to the beginning coder.
Image

User avatar
Plasma Man
Posts: 2035
Joined: Tue Jan 15, 2008 9:27 am UTC
Location: Northampton, Northampton, Northampton middle England.

Re: 0844: "Good Code"

Postby Plasma Man » Fri Jan 07, 2011 9:00 am UTC

I think this flow chart could be applied to anything, not just code.
Please note that despite the lovely avatar Sungura gave me, I am not a medical doctor.

Possibly my proudest moment on the fora.

thelastholdout
Posts: 14
Joined: Mon Mar 16, 2009 6:24 am UTC

Re: 0844: "Good Code"

Postby thelastholdout » Fri Jan 07, 2011 9:14 am UTC

Randall finally mentions Android.

The trouble is, being non technical, I don't know where Android is supposed to be on that flow chart. Having sold the phones and seen how well they've worked (Esp. the ones by Motorola and HTC) I'm inclined to think that it's under "Code well" and "Good code." I also know it's based on Linux, which many computer savvy people seem to like. But then again, my opinion doesn't come from a programmer's perspective; more of an end user's. Randall's opinion won't change mine, but I'd still like to know what his point is. Help?

User avatar
Quicksilver
Posts: 437
Joined: Wed Apr 29, 2009 6:21 am UTC

Re: 0844: "Good Code"

Postby Quicksilver » Fri Jan 07, 2011 9:47 am UTC

So this is why people are so interested in Cloud Computing. The only good coding exists in the cloud!

SolarNet
Posts: 2
Joined: Fri Jan 07, 2011 9:34 am UTC

Re: 0844: "Good Code"

Postby SolarNet » Fri Jan 07, 2011 9:51 am UTC

Personally I think you need a line to to "Is it done yet?" from "Are you done yet?" labeled "No, but I need money"

Tag
Posts: 19
Joined: Wed Sep 03, 2008 10:08 am UTC

Re: 0844: "Good Code"

Postby Tag » Fri Jan 07, 2011 10:27 am UTC

HURD is definitely "take ages to do it right" - it started development in 1990 as the kernel for the GNU project, and is still not really finished; GNU tools are now run almost exclusively on the Linux kernel, which overtook HURD in five months in 1991.

I'm sure Android isn't the worst code out there, but it did get a lot of flak in the early days for being buggy and hard to develop on. It does work - note that the 'code it fast' route is the only way on that flowchart that you actually ever get (almost) working code - but I'm guessing still isn't all sweetness and light under the hood.

pies
Posts: 1
Joined: Fri Jan 07, 2011 10:28 am UTC

Re: 0844: "Good Code"

Postby pies » Fri Jan 07, 2011 10:30 am UTC

I think that good code is the code that paid my own and the client's bills.

m4ndi
Posts: 3
Joined: Fri Jan 07, 2011 11:44 am UTC

Re: 0844: "Good Code"

Postby m4ndi » Fri Jan 07, 2011 11:52 am UTC

Nice, very nice. Mandy like.

---

ex-codemonkey, brain literally fried bananas.

exh
Posts: 4
Joined: Mon Jun 14, 2010 12:35 pm UTC

Re: 0844: "Good Code"

Postby exh » Fri Jan 07, 2011 11:56 am UTC

Erm, well there's really only one loop here. For good code you need to code well.

Maybe you code well fast, maybe you code well slow, but if you don't code well, you won't get good code.

If you code well fast, you'll get the project done before the requirements change, but the requirements will change anyway and then you need to code well fast all over again. If you really have coded well, these changes will be much simpler to implement.

User avatar
neoliminal
Posts: 626
Joined: Wed Feb 18, 2009 6:39 pm UTC

Re: 0844: "Good Code"

Postby neoliminal » Fri Jan 07, 2011 1:02 pm UTC

Code: Select all

function code($var) {

$result = array("Good", "Fast", "Right");

if ($var == "Right") { return "This is the Right code." }

$var="Fast"?return "Fast Code";

if ($var === "Good") {
  return "True";
  }

}
http://www.amazon.com/dp/B0073YYXRC
Read My Book. Cost less than coffee. Will probably keep you awake longer.
[hint, scary!]

Semper_Phoenix
Posts: 2
Joined: Fri Jan 07, 2011 1:06 pm UTC

Re: 0844: "Good Code"

Postby Semper_Phoenix » Fri Jan 07, 2011 1:10 pm UTC

Kobukson wrote:This would make a nice print to go next to the old Tech Support Flowchart ^^


And it would be a most awesome T-shirt, please :D

captHij
Posts: 15
Joined: Mon Jun 08, 2009 6:37 pm UTC
Contact:

Re: 0844: "Good Code"

Postby captHij » Fri Jan 07, 2011 1:19 pm UTC

I am generally pretty laid back with respect to xkcd and what [I think] Randal is trying to say. I have to say, though, this is the first time that he really cut this close to "home." And it hurts.

*sobs*

Now please excuse me, I am going to go curl up under my desk in the fetal position for the rest of the day and hope that I can find a way to come back to work on Monday....

User avatar
jc
Posts: 356
Joined: Fri May 04, 2007 5:48 pm UTC
Location: Waltham, Massachusetts, USA, Earth, Solar System, Milky Way Galaxy
Contact:

Re: 0844: "Good Code"

Postby jc » Fri Jan 07, 2011 2:11 pm UTC

Negated wrote:You need goto to get to good code.

Heh. I've seen a couple of cases where I could make a chunk of code smaller, faster and much more readable by the introduction of one or two judicious goto statements. It was fun watching how flustered the more doctrinaire programmers got trying to argue that it was "bad code".

Of course, Dijkstra's original paper was more of a comment on missing language structures and problems with programmers' "culture" than it was about the moral qualities of a goto. The above cases were when working in C (or C++, which has the same problems). When working in perl, for example, I really haven't felt the lack (though I have in python, and can't quite explain why).

I've also had a bit of fun using the anti-goto doctrine as a critical part of a proof that good code can't exist. You start with a definition of "good code" that includes "no goto statements". You then observe that, whatever language you are working in, the code must ultimately be translated to machine code before it can execute. All machine languages make heavy use of goto statements, both absolute and conditional. Therefore, by the definition, machine code can't be "good code". However, the machine code is logically equivalent to the source code, in whatever language you're using, and must therefore have exactly the same properties. So your source code, if it runs correctly, is equivalent to a specific string of machine code, which we know is "bad code" because it contains gotos, proving that your code is also "bad code".

(I tend to consider this a distant relative of all the "all integers are interesting" joke, but it's interesting that few programmers respond to the above proof by laughing. Maybe when you disguise a joke well enough, people don't recognize it as such, and take it seriously. Anyway, I've seen people go to great lengths trying to find a hole in the above reasoning, which just might be even funnier than the "proof" itself.)

User avatar
VectorZero
Posts: 471
Joined: Fri Nov 02, 2007 7:22 am UTC
Location: Kensington

Re: 0844: "Good Code"

Postby VectorZero » Fri Jan 07, 2011 2:43 pm UTC

Lewton wrote:There's no such thing as good code
only good enough
The enemy of good is better.
Van wrote:Fireballs don't lie.

dahauns
Posts: 1
Joined: Fri Jan 07, 2011 2:42 pm UTC

Re: 0844: "Good Code"

Postby dahauns » Fri Jan 07, 2011 2:49 pm UTC

I just can't help but wonder...has no one here ever worked with a language with proper refactoring support?

User avatar
SpringLoaded12
Posts: 350
Joined: Wed Oct 08, 2008 1:58 am UTC
Location: Guarding the Super Missile
Contact:

Re: 0844: "Good Code"

Postby SpringLoaded12 » Fri Jan 07, 2011 4:15 pm UTC

Such pessimism, Randall! Cheer up :D

The Google Labs App Inventor, which lets you use visual interfaces to make apps for Android, is surprisingly difficult to use when you've gotten used to typing in code from scratch. HTML, Java, and C++ ftw.

I wrote a small text-based adventure in Java, using only one class. Responses to commands are handled by if statements and occasional else statements, each room in the dungeon has a while loop, and there's a fair number of easter eggs. Is this fast code that almost works or correct code that's good enough?
"It's easy to forget what a sin is in the middle of a battlefield." "Opposite over hypotenuse, dipshit."

SolarNet
Posts: 2
Joined: Fri Jan 07, 2011 9:34 am UTC

Re: 0844: "Good Code"

Postby SolarNet » Fri Jan 07, 2011 4:45 pm UTC

jc wrote:I've also had a bit of fun using the anti-goto doctrine as a critical part of a proof that good code can't exist. You start with a definition of "good code" that includes "no goto statements". You then observe that, whatever language you are working in, the code must ultimately be translated to machine code before it can execute. All machine languages make heavy use of goto statements, both absolute and conditional. Therefore, by the definition, machine code can't be "good code". However, the machine code is logically equivalent to the source code, in whatever language you're using, and must therefore have exactly the same properties."


Couldn't you theoretically use bad code (defined as code using gotos, i.e. jmp) to create a compiler/interpreter that prevented the use of jmps when code was executed... even if it would normally use jmps?

I mean I guess that would kind of be cheating... As the interpreter would have to partially execute the code to figure out which piece of assembly to toss in front of the CPU next. Just a thought.

CodexDraco
Posts: 19
Joined: Fri Sep 24, 2010 1:37 pm UTC

Re: 0844: "Good Code"

Postby CodexDraco » Fri Jan 07, 2011 5:18 pm UTC

SolarNet wrote:
jc wrote:I've also had a bit of fun using the anti-goto doctrine as a critical part of a proof that good code can't exist. You start with a definition of "good code" that includes "no goto statements". You then observe that, whatever language you are working in, the code must ultimately be translated to machine code before it can execute. All machine languages make heavy use of goto statements, both absolute and conditional. Therefore, by the definition, machine code can't be "good code". However, the machine code is logically equivalent to the source code, in whatever language you're using, and must therefore have exactly the same properties."


Couldn't you theoretically use bad code (defined as code using gotos, i.e. jmp) to create a compiler/interpreter that prevented the use of jmps when code was executed... even if it would normally use jmps?

I mean I guess that would kind of be cheating... As the interpreter would have to partially execute the code to figure out which piece of assembly to toss in front of the CPU next. Just a thought.


You can't avoid jumps, these are a fundamental feature of computer architecture. Even something as simple as an if require al least a jump.

@jc Good code is about humans, not machines. And I agree gotos are largely underrated.

wsdenker
Posts: 15
Joined: Sat Aug 29, 2009 6:13 am UTC

Re: 0844: "Good Code"

Postby wsdenker » Fri Jan 07, 2011 5:55 pm UTC

thelastholdout wrote:Randall finally mentions Android.

The trouble is, being non technical, I don't know where Android is supposed to be on that flow chart. Having sold the phones and seen how well they've worked (Esp. the ones by Motorola and HTC) I'm inclined to think that it's under "Code well" and "Good code." I also know it's based on Linux, which many computer savvy people seem to like. But then again, my opinion doesn't come from a programmer's perspective; more of an end user's. Randall's opinion won't change mine, but I'd still like to know what his point is. Help?


Android would be under the "code fast" line. The joke is that "good code" might be achievable, but nobody quite knows how it comes about. It has nothing to do with whether Linux is involved or how stable and functional the software appears to be from a user's perspective. Coding quickly is often coding recklessly and one does frequently end up with a functional product but it's hell for developers to maintain.

Developers who pursue the "code well" line are attempting to build the Mr. Fusion powered engine from Back to the Future (the elegant, perfect machine). Most often one ends up falling short because it takes time to code well and then the specifications change while one is in the process of doing so and, well, they are trying to build a fusion powered engine. Those who pursue the "code fast" line end up with a Rube Goldberg contraption under the hood that nobody knows how all of it works, though a few people understand some of the parts.

It is a little bit funny from a programmer's perspective that you said "Randall's opinion won't change mine." You'd have to understand what you're meant to have an opinion about. From your perspective what's under the hood is magic and it's hard to have an opinion about how wizards accomplish it if the end result appears the same. ;)


Return to “Individual XKCD Comic Threads”

Who is online

Users browsing this forum: mscha and 35 guests