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)?
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)?
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.// 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();
}