![]() |
|
Don't rewrite your old code |
Neil Black
Member #7,867
October 2006
![]() |
Why use that old cart? When you can get... the Ultra-Cart 5000! Its fast, its sleek, its wheels are always compatible with the cart and the axle*. And what's more, it requires no elephant** and is assassin resistant***. Only two hundred seventy-six EASY payments of $99.99****! Supplies are limited, buy now. ----------------------------------------------------------------------------------- *Wheel-axle-cart compatability not guaranteed.
|
kronoman
Member #2,911
November 2002
![]() |
I have a double moral. I like to rewrite from scratch my own code, because I do it as a hobby, and is fun, and educational, and I usually get better results. I don't like, and I don't think that is good (usually, there are cases were is good) to rewrite business code from working systems that are used to generate revenue. In those systems, I think that the KISS approach, and the "don't fix it until it is broken" really apply. |
Trezker
Member #1,739
December 2001
![]() |
That's what branching is for. |
Neil Black
Member #7,867
October 2006
![]() |
my old code needs rewriting. And this is only a few weeks old it works, though.
|
gnolam
Member #2,030
March 2002
![]() |
Quote:
rect(buffer, 0, 410, 640, 480, makecol(255, 255, 255)); rect(buffer, 1, 411, 639, 479, makecol(192, 192, 192)); rect(buffer, 2, 412, 638, 478, makecol(128, 128, 128)); rect(buffer, 3, 413, 637, 477, makecol(96, 96, 96)); rect(buffer, 4, 414, 636, 476, makecol(64, 64, 64)); rect(buffer, 5, 415, 635, 475, makecol(32, 32, 32)); rectfill(buffer, 6, 416, 634, 474, makecol(0, 0, 0));
Ever heard of for loops? And for the love of the Antichrist, stop using rest() timing... -- |
Taiko Keiji
Member #8,307
February 2007
![]() |
I would look into using a DATAFILE to store your images. it would make it easier to keep track of later. Life could be better, machines could program themselves. Taiko Keiji- |
Neil Black
Member #7,867
October 2006
![]() |
I told you it needs re-writing.;D
|
Johan Halmén
Member #1,550
September 2001
|
At the present I'm very attempted to rewrite one application. It has a rather large allegro dialog struct and the indices are somehow wrong. Months ago I added something to the dialog and never got it ready. Now I need to make it ready and I have a hard time debugging it. It compiles and runs, but doesn't do the thing it should. And it is because indices are wrong. It's all about image manipulation and I have these radio buttons for whether creating a new file or overwriting the old. And some buttons for jpg quality. So when I wan't to make resized copies of all images in a folder, it overwrites all images with b/w, unresized, really screwed up versions of the images. The main problem is only in my coding style. I haven't figured out how to write maintainable code what comes to allegro dialogs. It would be nice to have a way of using macros or something for the indices, so if you add one item in the middle of the dialog struct, you wouldn't have to change the indices all over the code. I bet masking or any other gui lib handles this better. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest. |
Bruce Perry
Member #270
April 2000
|
That code does not need rewriting!! I read it quickly and understood it pretty easily. I don't know what all the functions you haven't included do, but there's nothing in there that looks particularly bad. Fixing the location of the clear_keybuf call is a question of moving the line from one place to another. The 'rest' timing thing is a bit harder to fix, but only because Allegro has such a horrible timing API (it doesn't even have a 'get current time' function) - and it's still only a question of writing more code, not throwing the old code away. (The problem is that the code running in between calls to 'rest' also takes time, thereby slowing the game down on slower computers, since gnolam didn't have the manners to tell you.) You could change it to use datafiles, but you don't have to; I don't see how it makes it easier, it just keeps everything nicely in one file and allows you to compress it. And there is no need to write that series of rects as a loop; the existing code is short and it's clear, and if you use a loop, you'll have to generate the series of colour values somehow - perhaps using an array. It'll also be slower. There's just no point. Seriously, don't rewrite that code. There's nothing fundamentally wrong with it. There may be tweaks you can make, or you may have to rethink parts of it as you add to the project (but only if they don't work or start getting messy), but that's it. Quote: I haven't figured out how to write maintainable code what comes to allegro dialogs. Sounds to me as if that's your only reason not to like the project. I also remember having a bit of trouble with that myself. I think I built the array up at run time, using a macro that fills all the fields in and then increments a counter - and then, when I needed to know an index, I just added a line that copied the value of the counter variable. That would be a bit of a 'rewrite', but you could still use a fair amount of creative copying, pasting, searching and replacing to get it done. -- |
Johan Halmén
Member #1,550
September 2001
|
I use Julien Cugniere's dlg editor, which is actually very good. As good as the whole damn allegro gui system deserves. Worth its price, like Gimp. The editor does some nice things, it aligns all dialog entries nicely, you can muve each entry up or down in the struct (changing draw order), it draws even rects for custom procs. But when changing the order, you have to figure out the new indices and change your code manually. And that's the pain. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest. |
Neil Black
Member #7,867
October 2006
![]() |
Did I mention that I have clear_keybuf() in almost every function? For some reason I couldn't get the dialouge to work any other way (the game would immediately read a second keypress and close the dialouge before the player could read it.)
|
Bruce Perry
Member #270
April 2000
|
Are you using key[] to check for your keys? All you're doing there is reading from an array, without changing its contents. The key[] array is the status of each key: whether it's held or not. If you are using Allegro's GUI, then that uses readkey() to detect its key-presses. You should consider whether readkey() is better for your purpose too. You can use readkey() to get a key from the buffer - and have it removed from the buffer so nothing else can read it again - and if you don't want the function to block, you can call keypressed() first to check whether there is a key in there. See the docs for more information. If you indeed find that key[] is more appropriate, then why don't you call clear_keybuf() in just the right place, just before you show the dialogue? -- |
GullRaDriel
Member #3,861
September 2003
![]() |
Possumdude0: It is because your code is a mess. "Code is like shit - it only smells if it is not yours" |
Bruce Perry
Member #270
April 2000
|
Ta gueule. -- |
Kitty Cat
Member #2,815
October 2002
![]() |
clear_keybuf doesn't touch the key array. It just clears the keypressed/readkey queue. The only (valid) way to modify the key array is to press or release a key on your keyboard. -- |
Goalie Ca
Member #2,579
July 2002
![]() |
Quote: Ta gueule.
Tu peux la fermer? Don't re-write old code. Write it correctly in the first place. If it turns out not to be flexible or adaptable enough then you'll have to redesign it from scratch. edit: damn my post button skills are too fast! ------------- |
Thomas Fjellstrom
Member #476
June 2000
![]() |
Quote: If it turns out not to be flexible or adaptable enough then you'll have to redesign it from scratch. That is what is implied by "rewriting old code". You would NEVER rewrite an app the same way twice. Unless it was a perfectly coded piece of ART that you somehow lost the source to. -- |
Matt Smith
Member #783
November 2000
|
Quote: It has a rather large allegro dialog struct and the indices are somehow wrong. Months ago I added something to the dialog and never got it ready. Now I need to make it ready and I have a hard time debugging it. It compiles and runs, but doesn't do the thing it should. And it is because indices are wrong. I use defines for this, although enums would be better (I have been doing this since before I knew C thoroughly) This list of defines (or enum) needs to kept manually in sync with changes to the dialog, but it saves shlepping through the rest of the code. Hopefully, the dialog editor in DevAlleg will automatically maintain this list by associating the 'ID' with the relevant index. This has stalled because I want to parse the entire file for everything, because dlg's way of doing it does not preserve comments etc., and does not have automatic run-time initialisation code refactoring.
|
Kitty Cat
Member #2,815
October 2002
![]() |
Quote: I use defines for this, although enums would be better (I have been doing this since before I knew C thoroughly) This list of defines (or enum) needs to kept manually in sync with changes to the dialog, but it saves shlepping through the rest of the code. This is what I do in my ogg_encoder tool for apeg (which relies quite a bit on object "positions").
That way if I add or remove a widget, I just need to modify the one macro below it, and all the macros in the dialog remain in sync. -- |
GullRaDriel
Member #3,861
September 2003
![]() |
Bruce Perry said: Ta gueule.
Hey Bruce, do you have a problem ? Even if is your French is good, it is not good enough to crush me at French bashing, baby Now, for your French practicing, a little bit of informations: Goalie Ca said:
Tu peux la fermer? That is the difference between the French and Canadian speak ;-) You Canadian are more courteous than us the French ;-) ( and even more courteous than people learning French. ) Mark Oates: sorry. I did not want to derail the thread. PossumDude0: Were you really shocked ? If so I tell you now there was no reason as it was joking. If not, heh, have a nice day. Now, back on the thread rail: EDIT: "Code is like shit - it only smells if it is not yours" |
Bruce Perry
Member #270
April 2000
|
Whoa. All that reply to a post with two words in it! Your post just didn't seem funny. It seemed little more than an insult. If I can take it wrongly, then a lot of people could. It was worth my posting that, because now it's painfully clear you meant it as a joke (I wondered if you were going to flaunt your native French at me -- |
Goalie Ca
Member #2,579
July 2002
![]() |
In canada we have a saying for "english people" who just don't get it... Quote: Tête-Carré
------------- |
GullRaDriel
Member #3,861
September 2003
![]() |
My my my, Bruce. We misunderstood each other ! Lets say it is OK now While I wrote my answer I was remembering the long talk we had on irc some times ago, and your post made me a little bit angry ( as I was really joking PossumDude0 this time ). Bwahbwahbwahbwah, everything is under control now :-)
"Code is like shit - it only smells if it is not yours" |
Neil Black
Member #7,867
October 2006
![]() |
I just noticed something in my code. It looks like KEY_PLUS_PAD will decrease the speed, and KEY_MINUS_PAD will increase it!?
|
HoHo
Member #4,534
April 2004
![]() |
It is quite logical in my oppinion, you are changing friction. When you lessen the friction your whatever_it_is will move faster. __________ |
|
|