Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 22:33 18 Jul 2025 Privacy Policy
Jump to

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 : Tidy programs

     Page 2 of 2    
Author Message
djuqa

Guru

Joined: 23/11/2011
Location: Australia
Posts: 447
Posted: 03:53pm 21 Jan 2013
Copy link to clipboard 
Print this post

  shoebuckle said   [
Maybe I am of the old school, but I have seen enough to know that Functions and Subroutines cause less problems in a maintenance shop when they have a single entry point and a single exit, and I believe that this is still true today.

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.

Edited by djuqa 2013-01-23
VK4MU MicroController Units

 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 09:39pm 21 Jan 2013
Copy link to clipboard 
Print this post

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??
Edited by MOBI 2013-01-23
David M.
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4038
Posted: 10:07pm 21 Jan 2013
Copy link to clipboard 
Print this post

Generally languages don't do it like that, but generally BASICs do.

John
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 10:19pm 21 Jan 2013
Copy link to clipboard 
Print this post

  Quote  Generally languages don't do it like that, but generally BASICs do


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: Australia
Posts: 122
Posted: 10:24pm 21 Jan 2013
Copy link to clipboard 
Print this post

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: Australia
Posts: 819
Posted: 11:04pm 21 Jan 2013
Copy link to clipboard 
Print this post

  Quote  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 :)


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: Australia
Posts: 122
Posted: 12:33am 22 Jan 2013
Copy link to clipboard 
Print this post

  Quote  You may as well use a "gosub" and global variables.

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?

Edited by graynomad 2013-01-23
Rob Gray, AKA the Graynomad, www.robgray.com
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 12:46am 22 Jan 2013
Copy link to clipboard 
Print this post

  Quote  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.


"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. . Good to touch base again.
David M.
 
graynomad

Senior Member

Joined: 21/07/2010
Location: Australia
Posts: 122
Posted: 12:50am 22 Jan 2013
Copy link to clipboard 
Print this post

  Quote  elicit an appropriate vehement exclamation.

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: Australia
Posts: 819
Posted: 01:13am 22 Jan 2013
Copy link to clipboard 
Print this post

  Quote  BTW, speaking of putting things down, what about ozelecforum?



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.
 
     Page 2 of 2    
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025