How do you code?

For everything that's not in any way related to PureBasic. General chat etc...
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

How do you code?

Post by srod »

Hi,

I was just looking at some of the code behind what will be a large application and feeling a little guilty (in a strange way) that I've not really planned this through! It's a case of sit down, have some idea what I need to do next, and code away!

If I code myself in to the equivalent of a cul-de-sac then I backtrack, delete parts of the code, and go again!

It's not very efficient and does produce some sphagetti like code on occasion! But I find 'planning' my work to be tedious! I'm a 'get stuck in and damn the consequences' type!

How do you code?

Does anyone do any kind of planning on paper, draw some flowcharts perhaps?

I'm particularly interested in seeing how many others have adopted an approach similar to my 'John Wayne' type cowboy philosophy. Or am I the only one? :P
I may look like a mule, but I'm not a complete ass.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Every time you're about to write some spaghetti code, don't do it.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Trond wrote:Every time you're about to write some spaghetti code, don't do it.
That would stop me coding! :)

I don't intend the spaghetti, it just kind of develops!
I may look like a mule, but I'm not a complete ass.
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

Blindfolded, with a brail keyboard, with the monitor off, using my toes to type...

Don't even ask how I debug the things!
Character
Enthusiast
Enthusiast
Posts: 337
Joined: Mon Aug 07, 2006 3:51 pm
Location: Netherlands

Post by Character »

approach similar to my 'John Wayne' type cowboy philosophy. Or am I the only one?
Hahaha, no. You are not the only one.
I've got a method you can call the "that damn kid jumped into the swimming pool again" approach:

Code: Select all

Repeat

I want too much: get myself stuck: cry for help: get help: (than think I'm  kind of stupid): try again: get results:  then very proud: want even more..

Until Kid = Adult

Cessante causa cessat effectus
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Well, like a popular sports wear manufacturer once said...

"JUST DO IT!"

Kinda' 3 step workout:

1.) Have an idea, start coding.
2.) If something works, great. If not, move along.
3.) If it gets to complex dump the whole project and leave it to the experts.
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

:lol:
I may look like a mule, but I'm not a complete ass.
Killswitch
Enthusiast
Enthusiast
Posts: 731
Joined: Wed Apr 21, 2004 7:12 pm

Post by Killswitch »

I have a template .pb file that I use which is full of commented out areas which help split up my code and make it easier to get things going.

Most of the time I'll open up a blank file in the editor and hammer out the programs procedures, test it, then move it into my actual source. The final thing then is just to hook up all the procedures in a simple loop and all is well :)

As for a plan I tend just to think things through, then deal with problems as they arise. I have a tendancy to replace large chunks of code if I think I have a better way to do things, or discover some fantastic trick on the forums.
~I see one problem with your reasoning: the fact is thats not a chicken~
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

I don't a defined way to do things, it depends on the kind of program or project i do.
Sometimes i use the wellknown "trying -> error" system, other times i don't. When fullscreen, I use to use a Beep_(200,20) at some line to detect some bug...

But i'd like to remark 2 things:
- when things fail and i don't know how to catch it, i get depressed.
- Most of times i don't know exactly what i want to do (first step above pointed by Fluid Byte), i get depressed again because nothing seems to work.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

srod wrote:
Trond wrote:Every time you're about to write some spaghetti code, don't do it.
That would stop me coding! :)
Hehe.

Here's the number one tip: Keep DRY.

DRY = Don't Repeat Yourself.
That means for example:
- If you use two equal lines in a sequence at two spots in the source code, move them into a procedure.
- If you use an line with direct data manipulation at two or more places in that line at four spots in the source code, move it into a procedure.
- If you find yourself typing somthing like this:
PrefsOptionA = ReadLong()
PrefsOptionB = ReadLong()
PrefsOptionC = ReadLong()
Put the options into an array and use a loop to modify it. When you need to access the individual items use indexes from an enumeration. Multiple types? Use multiple arrays.

I'm repeating it: Don't Repeat Yourself. Don't Repeat Yourself. Don't Repeat Yourself. Don't Repeat Yourself. Don't Repeat Yourself. Don't Repeat Yourself.


Edit: And before you start coding you must exactly what you need. If you don't know, find out! I never use flow charts for the flow of my tagliatelle, but I've used a "flow" chart to show the data representation of the program.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

:lol:

When I'm 'in the programming zone' the old grey matter just rushes ahead, and before I know it I've produced a hundred or so lines of code which, two hours later, leaves me scratching my head wondering what it was supposed to do in the first place?

And even if it does what it was supposed to do, I wonder just how the hell it does it? :)

Only kidding! My code's not as bad as I'm making out, but I still can't bring myself to grab a pen and paper and jot down a few algorthims or some psuedo-code etc. Just takes the fun out of it all!
I may look like a mule, but I'm not a complete ass.
User avatar
Guimauve
Enthusiast
Enthusiast
Posts: 742
Joined: Wed Oct 22, 2003 2:51 am
Location: Canada

Post by Guimauve »

When you write some code try to KISS -> Keep It Simple Stupid

How to KISS the code, split all big problem in as many smalls problems as possible.

DRY and KISS.

Otherwise you will feel like this :
Image
http://smiley-gratuit.eu/

Regards
Guimauve
Last edited by Guimauve on Sun Mar 25, 2007 5:08 am, edited 1 time in total.
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

I like WET and KISS... from my girlfriend. I start coding and it never fails she tries to distract me :twisted:
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

:lol:
I may look like a mule, but I'm not a complete ass.
Intrigued
Enthusiast
Enthusiast
Posts: 501
Joined: Thu Jun 02, 2005 3:55 am
Location: U.S.A.

Post by Intrigued »

I believe the problem is like Chess in one way.

It's hard to start coding from scratch and see all the "moves" you must take to get the code right.

"Move" here and you should have done some Select..Case statements back there.

"Move" there and you should have checked for that first and then if that was there then make sure you respond to each part of the question, in order to get to the right place.

Etc. etc.

First, make sure you have interviewed the company, group, person, organization, etc. that you are going to do the program for. Find out everything you possibly can about their needs AND wants for the program. The better you hammer that out up front the better off you are in the long run.

One idea would be to brainstorm what you want to accomplish with the program (or needs to be accomplished).

Decide which platform to code it in (PB, Flash, AMS, HTML, PHP, etc.)

Visually lay out the application, if it has a GUI, components (then code around them).

Then start coding.

*Now, go do as I say and not as I do* ;-)
Intrigued - Registered PureBasic, lifetime updates user
Post Reply