Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : Popping the Gosub stack...
Page 2 of 3 | |||||
Author | Message | ||||
Dylan Regular Member Joined: 17/06/2013 Location: NetherlandsPosts: 81 |
Yes and no. Grogster is clearly here to learn. Learning can involve making mistakes, no problem. I'm learning too (on the hardware front). Sometimes I wish I had listened to the advice my mother gave me when I was younger. "What advice?", you might ask. I don't know! I didn't listen. There is nothing whatsoever wrong with doing what you like with your own code. Sometimes a fix written in the spirit of the (somewhat poor) code will be sufficient. But for anything longer than about 100 lines of code (not a metric I subscribe to, but easy to understand nonetheless) it gets confusing. To me, at least. And I have some experience. |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9308 |
Yes I have, but I thought it was just me imagining things. When you mentioned it, I loaded one of my short programs(but still a couple of pages long - about 200 lines or so), and yes - you can scroll much faster in the smaller program then you can in the bigger one. Smoke makes things work. When the smoke gets out, it stops! |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9308 |
Thanks everyone else for info and links. This info is perhaps more interesting the writing the code is. PERHAPS my code might be in for a bit of a revamp/rewrite. Not sure about this - I will have to have a bit of a think about it, as it is freakin' huge at 770 something lines. Most of you here will NOT be happy to discover that my code is pretty much full of GOTO's... Now, in MY case, I can follow it just fine, and it works, and I am not planning on releasing it, so it does not really matter that others may not be able to read it as easily as they should be able to without all the GOTO's. Nevertheless, I don't want to be writing like that now, KNOWING that it is now not the way to do it. But rewriting 700 odd lines of code to remove gosubs, gotos and replace them with structured loops is not something I am willing to do at this point - it would just about be better to start a page-1 rewrite. I need to have a bit of a think about all this. What I CAN say, is that from the next program, I will be writing things differently, and not using gotos. In this case, I might just leave the 700+ line program as it is, because it is working the way I want, with the exception of the original post problem. With respect to that, I have just decided to use the EXIT command as mentioned back on page 1 of this thread. I know, I know - not what I should be doing, but it will solve my current problem. The code is 99% finished you see, and I really am not willing to rewrite things at 99% complete. Had I discovered all this bad karma about Goto back at the 50% mark or less, I would have probably changed what I had. This is not to say, that once I have it all running the way I want, that I won't print it all out on paper, and then look at developing a "Revised" edition of the code, which has the changes required to remove the Goto's. But for right now... Smoke makes things work. When the smoke gets out, it stops! |
||||
vk2sja Newbie Joined: 07/06/2013 Location: AustraliaPosts: 26 |
Hi All (Newbee first post), Without wishing to enter the debate surrounding poor programming practice. It is interesting to note that this very same functionality was in fact built into GW-BASIC:- Source: GW_Basic Manual I also find it interesting that other BASIC dialogs supported this with a POP statement. Something I didn't know. While I don't have strong convictions regarding this issue, one way or another, my personal inclination is that having such functionality may in fact be justified. Unless you intend to remove GOSUB from the language altogether. Having one without the other seems "incomplete" somehow. Regards, Steve. |
||||
Nick Guru Joined: 09/06/2011 Location: AustraliaPosts: 512 |
GOTO and GOSUB seems to be made out to be an infectious disease. I write games so I don't really care if other's can't follow my code, it's preferable actually. I've been using these commands since the early 80's and I have never run into problems. If anything, I've been able to create code which runs faster and more efficiently. When I got into Assembly Language, I was in nirvana! POPing stacks and self modifying code was the only way to get more speed from a 1Mhz system. It was a challenge coming up with new techniques and pushing the boundaries. Using GOTO and GOSUB doesn't frighten me at all but I will acknowledge that this is only appropriate for closed code of which it preferable others can't easily decipher. Anything else, needs to be made clearer and structured with comments if the requirement is for others to utilize or modify the code. Nick |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9308 |
Thanks for the pro-Gosub/Goto support guys! Perhaps we have a variation of Code Writing By Committee? (rhetorical) While I fully acknowledge that Goto's are "Undesirable" as of this thread, I have made the decision NOT to alter the code as it currently sits. Future programs will try to make no use of Goto's, as per this thread's suggestion, but as for my 770+ line program that is 99% finished, I am just going to stick with the gotos and gosubs and exit commands etc. When the time comes for a new version of the program(quite likely), I will, at that time, clean it all up to use more "Standard coding practice". Smoke makes things work. When the smoke gets out, it stops! |
||||
MicroBlocks Guru Joined: 12/05/2012 Location: ThailandPosts: 2209 |
770+ Is still small :) Rewriting after you finish can be very good. Most of the time you find out things while you are programming and after having a working version you know all the details and where you were having difficulties or had to go bend a few rules. :) If you want i can do a review and see what can be made better. I do this daily so it is not a bother at all. Microblocks. Build with logic. |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9308 |
That is a VERY generous offer, TZA. I will take it under advisement, and perhaps PM you. Smoke makes things work. When the smoke gets out, it stops! |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3194 |
Don't worry, you are following a path that most of us have gone through in the past. My early stuff was full of gotos and similar "bad practices" but I have got better with time. If anyone is interested, MMBasic has 33 gotos in 50,000 lines of code. Geoff Geoff Graham - http://geoffg.net |
||||
Nick Guru Joined: 09/06/2011 Location: AustraliaPosts: 512 |
Donut Dilemma game (10 Levels): 162 GOTO statements 4 GOSUB statements 847 lines (many are multi-statement lines) Time to create from start to finish (including graphic design): 2 months No GOTO errors. I'm such a bad boy! |
||||
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3804 |
A program I developed a while back ended up as about 118,000 lines and has no GOTOs at all. Never needed any. Once you get used to not using any, you get faster at writing code because there are no or very few oddities to hunt down. John |
||||
MicroBlocks Guru Joined: 12/05/2012 Location: ThailandPosts: 2209 |
It all depends on the needs. Maintainability, speed or space constraints. Using lots of gosubs can slow things down, if that makes a program to slow or not functioning at all (like in games), you need to get rid of them. Goto is much faster. Reusing parts of a program to save space can also be achieved with gotos. So, you have a PC with lots of memory and insane amounts of processing power. Don't use goto, structure it. You have a small microcontroller with lack of speed and memory constraints. Use whatever to get the job done. Even if you need to breek all the rules. This still means you should start without using gotos and maintain structure. But if that fails, all rules can be broken. Microblocks. Build with logic. |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9308 |
Thanks everyone for you comments. This has been a very interesting thread for me! @ JohnS - 118,000 lines?!??!!! Were you helping to write Windoze? Smoke makes things work. When the smoke gets out, it stops! |
||||
Nick Guru Joined: 09/06/2011 Location: AustraliaPosts: 512 |
If I were to "unroll" the 875 lines of my game code, the length of the program would probably balloon out to 3 times it's size. I find it awkward having a single command per line. I have a modular approach to my coding. I usually pack many commands together as a module. I know that a block of say 10 lines has a certain function... rather than several screens to do that same function. I find it far easier to analyse and debug a single tight block than constantly scrolling up and down to see the entire module. That's my style and that's how I work better and faster. Everyone has their style. In the end, you have a great product that works without bugs, it's all good. Nick |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9308 |
I guess it must therefore be true, that there is no "Perfect programming procedure" so to speak - whatever works at the end of the day. This is not to dismiss what we have been talking about in this thread. While lots of Goto's and Gosubs etc may not be exactly ideal coding practice in the generally accepted sense, if the code still runs OK like that, and you are NOT contributing to open source, then it would seem you can do whatever you want. BUT if you are co-developing something, or are planning on releasing the source to others, then I guess that is when you really need to stick more to the structured programming concept, so that other contributors can more easily follow it and add to it. I guess we could go on debating and discussing this forever. Smoke makes things work. When the smoke gets out, it stops! |
||||
MicroBlocks Guru Joined: 12/05/2012 Location: ThailandPosts: 2209 |
I agree with the style of keeping blocks of code within a screens height. Especially languages that have { and }. But For/Next Do/loop/While/until etc have the same 'problem' when they are nested deep. In C(#) add try/catch/finally and code ends up not like spaghetti but like unions. :) Nothing worse then to scroll down only to see: [code] } } } break; } a=1; } [/code] Luckily many editors can 'collapse' and expand blocks. I use my widescreen in portrait mode to get lots of lines. 120 characters by 96 lines. Makes reading code much easier as i do not really like long lines. Microblocks. Build with logic. |
||||
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3804 |
118KLOC (K lines of code) isn't big. Heck, only about twice the size of MMBasic and I reckon from the sounds of it took me longer than twice the time. Windows is millions of lines. John |
||||
Dylan Regular Member Joined: 17/06/2013 Location: NetherlandsPosts: 81 |
First of all, If we wish to count lines of code, we should not regard them as "lines produced" but as "lines spent". - Edsger Dijkstra On the other hand, KLOC is a vaguely useful estimate. There is at the very least a correlation between development time and code size. Also, as Fred Brooks pointed out in The Mythical Man-Month, and Steve McConnell reconfirmed in Rapid Application Development, development time does not increase linearly with lines of code written. JohnS, Did you write all 118K lines yourself? Or did that include libraries? My previous professional experience was primarily with Borland Delphi. The libraries I was linking to had roughly 100k lines of importance too. And those were calling Windows. Unsurprisingly, there was occasionally a bug (not blaming either Borland or Microsoft here). Yes, I have single-stepped through IE machine code to confirm the bug was not at my end. Yes, I found a work-around. 118KLOC is tiny compared to modern GUIs, sure. But it is huge by comparison with what can be comprehended by any single programmer at the same time. |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9308 |
Is Windoze REALLY millions of lines of code? Crikey - I am out of touch, on quite a few things. While I fully expected Windoze to be a few hundred thousand lines, looks like I might have been totally wrong there too! However, how can you KNOW how much code Windoze consists of, as it is closed-source, and reverse-engineering it to see how many lines are there and how they actually wrote it, is illegal, and prosecutable if they find you have done it, so "millions of lines" would have to be a guess. An educated guess, but still a guess - correct? ...but I digress - we don't want to start talking about decompiling windoze! Makes me wonder how they manage to develop things like Windoze or Linux. I guess there are teams of people, all writing towards the finished product. Certain people concentrating on writing certain bits of code that do certain things, then they bring all that together at the end. If that is the case, you'd think that would be a natural bug-developing way of doing it, with several teams of code writers all potentially introducing their own bugs to the system. Once combined into one huge finished program or OS, bugs, bugs, bugs. But that is, I suppose, exactly what DOES happen - there have been plenty of bugs in Windoze over the years. They fix them all, but I guess in the OS writing department, bug-free is just about an impossibility. You get it as clean as you can, but there will always be something that gets missed. Perhaps I have been a bit unfair to Microsoft over the years, for bugs or other things that prevent the system from running smoothly(Linux users will not agree!). As I said, they(MS) normally fix the known bugs pretty quickly with a Hotfix. ...But I digress - again! Smoke makes things work. When the smoke gets out, it stops! |
||||
BobD Guru Joined: 07/12/2011 Location: AustraliaPosts: 935 |
Wikipedia thinks that Windoze XP had about 45 million LOC. |
||||
Page 2 of 3 |
Print this page |