Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
×

Comment Re:GTK is alright...but no raves (Score 1) 356

It may not be what the OP (Hosiah) wanted, but it's much better, cleaner, more maintainable code.

Hosiah's code:

No, I'm not kidding: a dialog box with three buttons should be:
D(H:50,W:200){M:"Quit without saving?",B1:"Save"(do_save()),B2:"Don't Save"(no_op&exit()),B3:"Cancel"(drop_quit())};


It's nice and all that he's managed to squeeze 7 or 8 lines of easily understandable code into 1 very long line that needs a fair amount of visual parsing to understand, but:

* Windows like this should not be specifying exact sizes - aside from all the time wasted determining what numbers fit, the end user is going to have a different font size, resolution, and screen size than you do. I hope your default window is resizable!

* It does not specify positioning - yes, it's assumed to be centered, but if you're all that interested in having so much control over the button text, it seems like an oversight to leave this up to the system.

* I hope you don't ever need to pass any params (or deal with any return values) from those functions.

* Yes, it's nitpicking, but his logic is wrong. The "Save" handler should save and exit, the "Don't Save" handler doesn't need a NOP for no reason, and the "Cancel" handler should do nothing (what on earth does drop_quit() do?

The art of programming does not consist in geting your program down to the least number of statements possible. It has much more to do with using the least amount *necessary to do the job and be clearly understandable*.

How is that code any better than this (other than being able to specify the button text)?
// Win SDK syntax off the top of my head from a long time ago...
// What is up with the <ecode> tag?
retval = MessageBox("Quit without saving?", NULL, MB_YESNOCANCEL);
if (retval != BM_CANCEL)
{
// Save first, then bail
// MB_NO == don't quit without saving
    if (retval == MB_NO)
        do_save();
 
    do_quit();
}
There. 10 lines, yes, but 2 are comments, 2 are just braces, and one is blank. Not a lot of stress on the old typing fingers, and a dramatic increase in readability and extensibility.
User Journal

Journal Journal: Snails as food

One important thing to know about puffer-fish is that their teeth grow quite rapidly and can get too big if not fed the right diet. If the teeth grow too big the puffer will not be able to eat and will starve. One of their favourite foods in the wild is the snail. The shell of a snail is enough to wear down the puffers teeth as he chomps through it.

User Journal

Journal Journal: New tank-mate - Cornelius

Gung-Ho has a new homey, a Sri-Lankan Red-Claw crab. Not my idea, but now that I've gotten rid of all of the guppies in the tank I listened to the gf when she asked if she could have him. Funny thing is that he's so afraid that the puffer will eat him that he doesn't come out at all.

User Journal

Journal Journal: Hmmmm

Nothing interesting to say, I'm removing all of the guppies tonight. The number of them is close to thirty now...definitely too many fish for a medium sized tank.

Julie wants to get a new crab for the tank, I'm not completely sold as I don't want to have to arrange the tank for a crab to get out of the water. Will have to research the specific type of crab it is.

User Journal

Journal Journal: Day Four

Gung Ho seems to be doing just great, I was concerned that he wasn't eating properly, but I think that was only due to stress as he seems to be eating fine now.

Went to the Aquarium shop and got him some frozen blood-worms, those seem to be going over very well with both him and the guppies. It's very amusing to see the guppies after having eaten the blood-worms as their stomachs turn bright red.

User Journal

Journal Journal: Gung Ho

I'm currently re-reading Cryptonomicon by Neal Stephenson (very chic in the /. circles I suppose, but deservedly so) and have decided to name the pufferfish Gung Ho after Bobby Shaftoe the "Gung Ho" Marine.

User Journal

Journal Journal: Firsts...an aquarium journal.

Accidentally clicked the link to look at my journal and realized that it was utterly devoid of content. This is just not something that I want to have be. So, here we are in my journal, I think I'll make the topic my new fish as he was acquired this afternoon.

Slashdot Top Deals

Software production is assumed to be a line function, but it is run like a staff function. -- Paul Licker

Working...