![]() |
Forum Index : Microcontroller and PC projects : Tidy programs
![]() ![]() |
|||||
Author | Message | ||||
djuqa![]() Guru ![]() Joined: 23/11/2011 Location: AustraliaPosts: 447 |
Always was, Always is, Always will be. Having multiple entry/exit points defeats the whole concept of 1 function does 1 task. If there is some condition that appears to require multi entry/exit maybe there needs to be a re-think of the code logic so there are separate functions for the separate conditions. e.g. [code] {N.B pseudo-coded, not in MMBasic} function Check(int a;) if a==1 then AddNumber(a,b,c) if a==2 then Multiply(a,b,c) end function AddNumber(int a,b,c) a=b+c end function Multiply(int a,b,c) a=b*c end [/code] TzAdvantage, Best practice NEVER gets old, it sometimes gets neglected. VK4MU MicroController Units |
||||
MOBI Guru ![]() Joined: 02/12/2012 Location: AustraliaPosts: 819 |
It puzzles me when using functions, the variable "ReturnValue" is used. I have always understood that the "return value" was actually assigned to the function. e.g. . . input "Enter length and width ",l,w print area(l,w) . . . function area(l,w) area = l*w end function . . . Perhaps there is something about MMBasic that this won't always work on?? David M. |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 4038 |
Generally languages don't do it like that, but generally BASICs do. John |
||||
MOBI Guru ![]() Joined: 02/12/2012 Location: AustraliaPosts: 819 |
I used Pascal for many years and all the programmes in that language I saw, if not always, nearly always did. VB does the same, but then, it is a Basic. To me, it makes a simpler programme to assign the value to the function. After all, sin,cos,tan etc are all functions with the value returned assigned to the function. Perhaps I am old fashioned? (emphasis on "old") ![]() ![]() David M. |
||||
graynomad![]() Senior Member ![]() Joined: 21/07/2010 Location: AustraliaPosts: 122 |
I'm the opposite (well I'm old as well but opposite in regard to this programming style), I find it quite peculiar to assign a value to a function, it all depends on where you're coming from I guess :) Rob Gray, AKA the Graynomad, www.robgray.com |
||||
MOBI Guru ![]() Joined: 02/12/2012 Location: AustraliaPosts: 819 |
Hi Rob, I just had a read through the Borland Turbo Pascal reference manual from many years ago in which it states that the result of the caluclations performed in the function statement section must be assigned to the function designator (function name) before execution of the function is completed. If this is not done, I don't see how the function can be included in a complex calculation. You may as well use a "gosub" and global variables. David M. |
||||
graynomad![]() Senior Member ![]() Joined: 21/07/2010 Location: AustraliaPosts: 122 |
Wash your mouth out with soap, such an abomination should be put down whenever encountered :) Yeah I know how it's done in some languages and I've written a heck of a lot of BASIC over the years, it's just that I come from a C background and as such it's a tad strange. No better or worse, just not what I'm used to. BTW, speaking of putting things down, what about ozelecforum? Rob Gray, AKA the Graynomad, www.robgray.com |
||||
MOBI Guru ![]() Joined: 02/12/2012 Location: AustraliaPosts: 819 |
"C" never really was a strong point of mine seeing as I lived in a Pascal world. Only C I've written is recently with arduino. I thought the suggestion of gosubs would elicit an appropriate vehement exclamation. ![]() David M. |
||||
graynomad![]() Senior Member ![]() Joined: 21/07/2010 Location: AustraliaPosts: 122 |
Yep ![]() I just edited my last post as well, yeah we don't talk much these days. Rob Gray, AKA the Graynomad, www.robgray.com |
||||
MOBI Guru ![]() Joined: 02/12/2012 Location: AustraliaPosts: 819 |
I Know it is a little OT. It never really had a theme and I was concerned from day one that it was a severe drawback. Most electronic topics have already been done and dusted in diverse forums. I couldn't see it going much past a chat room status. I think it is fading fast with long periods of inactivity. Hence my presence here. all the important info I have posted there is still in a folder on my pc, so not all lost. d. David M. |
||||
![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |