Graphic in on function

General FreeBASIC programming questions.
Post Reply
Gablea
Posts: 1104
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Graphic in on function

Post by Gablea »

Hi everyone

Would it be worth re doing my graphic sub functions into one single function to control all graphicals function in the program?

Would that make the software a little more stable?
paul doe
Moderator
Posts: 1733
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Graphic in on function

Post by paul doe »

Gablea wrote:...
Would that make the software a little more stable?
No, it will make it unreadable and impossible to maintain. What do you mean with 'stable'?
Gablea
Posts: 1104
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: Graphic in on function

Post by Gablea »

I keep getting kernal panic but not in the same spot.

Sometimes I can run the program for hours and nothing other times I can start it and then 30 seconds it would crash
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Graphic in on function

Post by badidea »

I assume you already compile with "fbc32 -w all -exx" for debugging?
Gablea
Posts: 1104
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: Graphic in on function

Post by Gablea »

Er no I did not know that was a option.

I’ll try that and let you all know.
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Graphic in on function

Post by badidea »

https://freebasic.net/wiki/wikka.php?wakka=CatPgCompOpt
-w additional error checking when compiling
-exx add error checking when running the program. Your program will be somewhat slower. If your program crashes, you'll probably get a message that tell you where it crashed.
paul doe
Moderator
Posts: 1733
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Graphic in on function

Post by paul doe »

Gablea wrote:I keep getting kernal panic but not in the same spot.

Sometimes I can run the program for hours and nothing other times I can start it and then 30 seconds it would crash
This has all the visage of:
  • An off-by-one error while accessing an array
  • Faulty pointer arithmetic, sometimes landing on the pad area (that would explain the erratic behavior)
As badidea tells you, compiling with -exx will probably reveal the error. Leave the program running as much as it needs to crash.

I don't know who or where you get the idea that putting everything in one giant function will help you. It's one of the worst things you could do, it will immensely hinder the maintainability of your program. You should be doing quite the opposite: separating the program into many small, cohesive functions that can work together and, preferably, statelessly.
Gablea
Posts: 1104
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: Graphic in on function

Post by Gablea »

@Paul Doe
Thanks for the advice I have been doing that having each Graphical function in its own code but then a "programmer" mate of mine told me i am a fool for having the graphics spread across the program. in his words I should have one file called graphics.bas and have each graphical function stored there (Im sure he was thinking it would be easier to locate the code)

oh a side note does anyone know if FB could run in windows 3.11? or is there any plans to port a compiler to Windows 3.11?
paul doe
Moderator
Posts: 1733
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Graphic in on function

Post by paul doe »

Gablea wrote:Thanks for the advice I have been doing that having each Graphical function in its own code but then a "programmer" mate of mine told me i am a fool for having the graphics spread across the program. in his words I should have one file called graphics.bas and have each graphical function stored there (Im sure he was thinking it would be easier to locate the code)
No problem. Now, modularizing the code (putting each related function in separate modules) is a good practice. Of course, sanity must also be applied: putting each single function into its own file will grind compile times to a halt, and just drive you mad =D

On the other hand, having really small functions (preferably they should be doing just one thing) is quite useful, as they allow you to compose the code into larger units. You then cluster together related functionality into a single file (module) and that's all the modularizing you'll ever need. Having all the graphics functions cramped together into one large file doesn't make the code easier to locate, quite the contrary.

So, your mate 'programmer' called you fool? Call him 'code monkey' -revenge is always sweet =D
Gablea
Posts: 1104
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: Graphic in on function

Post by Gablea »

I just tend to ignore him when he start to give “advice” I think he is use to working to much on web systems and I’m sure he had never compiled anything.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Graphic in on function

Post by MrSwiss »

Gablea wrote:in his words I should have one file called graphics.bas and have each graphical function stored there
There is absolutely nothing wrong with that, by contrast:
putting it all in one procedure, is a really bad idea!

Note: the two are massively different!
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: Graphic in on function

Post by grindstone »

Gablea wrote:oh a side note does anyone know if FB could run in windows 3.11? or is there any plans to port a compiler to Windows 3.11?
For Win 3.11 is only a DOS - frontend, the DOS version of FB should work with it.
Post Reply