LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Opinions: How do you "scratch up" you're program? (https://www.linuxquestions.org/questions/programming-9/opinions-how-do-you-scratch-up-youre-program-384456/)

TGWDNGHN 11-18-2005 04:22 PM

Opinions: How do you "scratch up" you're program?
 
Just curious... but when you all have a great idea of a program, where do you begin?


Do you flowchart? sketch out the structure of the program? sketch out the operation of the program? write it in psuedocode?


Just wondering

microsoft/linux 11-18-2005 05:06 PM

Personally? I just start coding:) I'm also probably still considered 'beginner', so I haven't learned the flowchart/structure/operation thing yet. Pseudocode seems pointless to me, because I generally know where I want to start

acid_kewpie 11-18-2005 05:09 PM

yep... just start. suss out a crude version of the core function, then flesh out the interface and all that as time goes on.. that's the point of being a hacker.

Mara 11-18-2005 05:29 PM

It depends how big the program is. If it's small enough to keep all the design in memory, I just write it. If it's bigger, I draw module structure and then start the most interesting one. Oh... and if it's GUI, I draw GUI first.

xhi 11-18-2005 07:51 PM

I always try to get the backend working, so all the pieces do the right stuff and just send output to console, file, whatever.. then throw a gui on it when everything is pretty smooth.. regardless of size, my personal projects almost never see paper, unless I run into a design problem(s) as Im going, then ill throw them down on paper...

TGWDNGHN 11-18-2005 09:07 PM

lol well personally for me, I prefer to write bottom up- getting all the functions, structures, ect/ set up before writing main()

I also like to code write away, excpet when I'm a little fuzzy about what exactly it is I want, in which I just write out what a simple interaction I would havewith the program- so I get an idea of it's Input, Output, and error handling

vivekr 11-19-2005 01:09 AM

I am just a beginner and I have tried almost all the ideas mentioned here. If I tend to to create all the submodules first before writing the main() I often endup in incompatible codes. Stubs for whatever that has been created and immediate integration helps me creating the solution quickly.
For larger programs some scribbling on how various classes and modules will interact does help.

Any suggestions and ideas are welcome
:)

TGWDNGHN 11-19-2005 08:39 AM

Once you get the hang of it- you master possibly the most fundamental UNIX Principals: Get it right the first time


You'll automatically learn how to develop the most efficient and effective code on the first round. Hence you'll find yourself writting "bottom up"- making all your components (functions. structures, classes, etc.) bullet-proof with a clear (and hopefully documented) interface you can use

Never assume you'll be the only one usin it. Personally, I ALWAYS document every component of my programs for future reference. And as a word of advice- keep a change-log on top. It REALLY HELPS you keep track of what you were doing...

Personally I"m self taught, so I'm very comfortable with all this stuff... but still being in High School I have to put up learning *Java*... its sickening


Lucky me I do everything within 10 seconds and my teacher and I both hate java and have the same background in C. So I usually do whatever I want and have begun writing a multiplayer RPG Game on the side. Because we had hurricanes over here- I forgot what part of the game I was working on.... but thank god I had my change log :D!!!

microsoft/linux 11-19-2005 12:35 PM

Quote:

Originally posted by TGWDNGHN

Lucky me I do everything within 10 seconds and my teacher and I both hate java and have the same background in C. So I usually do whatever I want and have begun writing a multiplayer RPG Game on the side. Because we had hurricanes over here- I forgot what part of the game I was working on.... but thank god I had my change log :D!!!

That's funny, I have the same experiance in my programming class(C++, I'm also 17). However, in my class, she always has work for us to do, but I'm way ahead of everyone else. I get the feeling that you also have a much higher skill level than me, I wouldn't know where to start on an RPG game. Ah well.....have fun in programming class:D!

xhi 11-19-2005 01:02 PM

>> (and hopefully documented)

very good point TGWDNGHN, code that is well documented as you go is much more valuable than a flowchart or anything written out on paper. that is a fact that is learned with experience though, hard to get it through when just beginning as youre so focused on the code itself...

>> I have to put up learning *Java*... its sickening

Lol. I know where you are coming from.. I learnt java years ago and have been a sworn enemy of it ever since.. I am c/c++ (prefer pure c++) however, recently I have been seeing that Java is not going away, and the improvement being made to the VM and also to the language itself are not helping it to go away.. I have found myself to be programming more and more in Java recently, I am actually about to get a job in a month in Java, and god forbid c#.. [head in hands] [sobbing].. oh my.. I would give up this in a second for C++, but the plain fact is that it is alot easier to code in Java, so it is much easier to get a job in Java...

thats all the rambling for now.. just hopefully can shine a little light on your dilemma, so you can see that if you learn it, it can be put to use for making cash money.... american currency, not that canadian stuff.. lol (no offense canada)

graemef 11-21-2005 10:20 AM

Quote:

possibly the most fundamental UNIX Principals: Get it right the first time
Funny I always thought it was: "Be prepared to throw the first version away"

It's very rare to get it right the first time but if you have a clear idea of what it is you intend to do then it it much easier to reenginner it to a better solution.

schneidz 11-21-2005 11:41 AM

#1. - make it work.
#2. - make it work better.
#3. - make it look pretty.

TGWDNGHN 11-22-2005 02:47 PM

I remember when I first started programming... I was 9 years old downloading free games off the internet when all of a sudden (being that I am incredibly creative and ambitious) I though "hey... what if I make my own game?!"

That was 7 years ago. Now, for what I program, I have so much experience that I ALWAYS get it right the first time. Thinking logically is second nature to me, so I never give it a second thought.

"Funny I always thought it was: "Be prepared to throw the first version away"

That sounds alot like a Windows Programmer :P


What I meant was that when you write a program, you want the design and interface to bedone correctly from the beginning- NEVER release a (knowingly) faulty or incomplete program and hope to fix it up with patches.

I mean... if oyu look at the code for alot of Linux programs (or at least the man pages, which are still more-or-less resemblant of the modern versions of the programs)- most of the code coems back from 1992 or 1996! Depending on the program, most of them seem as if they have been untouched... at least in a "significant" sense. Even so, you'll still find the older versions working just as fine as ever


They are heavily tested, their design has been carefully outlined and implemented- with a nicely drawn interface that is designed with change in mind.


Now THAT is what I call god programming.


So really... I always get it down right the first time- I don't look back saying to myself "aw shoot, I should have done it this way instead". The Design of the program is usually finalized on the first draft- the actual implementation is somewhat the same way. Sure you might make a mistake, get the order wrong, or realize you could have odne something jus a little more efficient- but those a insignificant degrees. When it comes to programming, a program's quality is best measured against it's design so you know how to work with and interface to it. Then the actual implementation may vary, but is usually not as important unless you have horrible programmers...


Which is why very few people here use Windows :)

graemef 11-23-2005 09:26 AM

"Plan to throw one away; you will, anyhow."
 
The quote is from Fred Brooks - Mythical Man month; quoted and endorsed by Eric Raymond in his The Cathedral and the Bazaar.

Sure it is possible to get trivial programmes working first time but any substantial programme - regardless of platform or language - will result in flaws creeping in. The point that Raymond presses home is that it will happen so be prepared for it because as you rewrite the second solution you will understand the problem much better and so you can produce a better product.

dmail 11-23-2005 10:11 AM

Personally i make some uml diagrams and then use pseudo code, before i even start to code. This method lets you see how thing interact and the best way of doing it, sorting out the logical errors without worrying about syntax errors. After this I then start to code and finish up by optimising any code which is a bottle neck.

alred 11-23-2005 01:09 PM

QUOTE :: by schneidz
"#1. - make it work.
#2. - make it work better.
#3. - make it look pretty."


how true , how true ...
infact to rephrase al steven from Dr. Dobb magazine :

#1. - make it work , is my first attempt and i'm the only one who use it

#2. - make it work better , is when i attempt to reuse some code for my 2nd program

#3. - make it look pretty , is when i finally try to publish it just for fun and for some kick , and feels like having your pants down infront of the public , so forget about "If It Ain't Broke, Don't Fix It" , its rather "If It Ain't Beautiful , Paint It !!" ...


:D

TGWDNGHN 11-23-2005 02:57 PM

Personally, I only use Pseduo code when I am going to publish some sort of code example I would like to share with my friends... it makes it alot easier to reimplement into other languages then trying to first translate the syntax of a language you don't already understand...


as an extreme example- it would be MUCH better to write something in psuedocode than assembly language... that would be too plainful for 99.9% of the population lol

BillyGalbreath 11-23-2005 03:58 PM

Like many that have posted here, I too just start coding. I like to start on the back-end of things then later on give it a pretty smile. Some of my friends dont see how I can do that on the bigger projects. I'll tell you what I always tell them: The bigger the project, the more fluid it is going to be. I change my mind almost constantly while programming. I create new ideas, I scratch old ideas, etc. If I am to try and write/draw the program out on paper, in the end it wont look and act anything like that at all. Planning is a waste of time. Just go with the flow. ;)

xhi 11-23-2005 04:03 PM

Quote:

If I am to try and write/draw the program out on paper, in the end it wont look and act anything like that at all. Planning is a waste of time. Just go with the flow.
I agree, and I try to carry that motto on to my real life also.. Planning is a waste of time. Just get drunk, er..um.. Go with the flow.

Mr_Munkey 11-23-2005 05:42 PM

If it's a really big program I'll write up some psuedo UML (hardly ever do I write correct UML). I'll also jot down some notes about different ideas for particular, more interesting, modules/classes. After that I just dive into getting the framework and back-end working. That way I can test to make sure certain things are going to work well before I get too involved in the front-end. Then I can just focus on how to best display the output, because I know what to expect.

Most of the time you'll make changes to your plans, and sometimes you'll even make some changes to code you already wrote in the same version of the program. Once you're getting ready to put the program out to the masses is when you need to make sure it works as flawlessly as possible. The fewer patches, the better you look. No getting caught with your pants down in public ;)

Somtimes you'll come back to a project you worked on a few months before. You'll look through the code and think to yourself, "Why didn't I just do it this way? Oh, yeah, I just learned how to do that last week." or something along those lines. You're always learning new things as you continue to write programs, so almost any program can be improved upon, with the exception of "Hello World". I suppose you could try to make it all 3-D, but you get my point.

tuxdev 11-23-2005 05:56 PM

I just make up all the .h files I need, then fill in the details.

alred 11-24-2005 02:09 AM

precisely !!
but sometimes i would like to entertain myself the possibility of whether we are being paid for coding(in one way or another) or not ... i mean what we published onto the public when we are getting paid might be totally different from when we are not paid at all ... heck !! we might just as well scrap the older "home/bedroom" version and start from scratch(maybe heavy reuse of better code) but this time a truely working "commercial"(though still a free software) version and with lesser "flashy" features too :p


QUOTE :: by xhi
" Just get drunk, er..um.. Go with the flow"

good point ... but to think about it ... its totally possible to create better quality music when we are kind of drunk , but how about amature(professional??) coding ... sometimes i heard people saying that hackers/programmers all love music and sometimes influence by it(either classical or rock) and some of them might be pretty good musicians too ... Go with the flow ^_^

.

TGWDNGHN 11-24-2005 11:07 AM

When I work on a project... the last thing I ever think about is the actual language or implementation.

I always start with the logic- "hmm... what is the most logicial way to systematically solve this problem or perform this function?"


All the planning would involve balancing speed with efficiency. Even in these days that we have lots of RAM storage... once you become a C programmer you still can't help but strangle your program of every byte you can spare. Now depending on the program this can be good or bad. For example: if you are using a Bubble Sort (I don't see why yu' ever use one though), then one byte of storage would determine whether it would continue running even though the array is sorted, or just exit. You really need to think about whether it is actually worth it.



The beauty in a program comes from a design... if it is flawed- then there is no use on trying to perfect the code for imperfect logic. That is why I never rewrite code. Yes, I'll implement new functions, yes- I might even replace a small section of the design for one better suited for a different situation- but I never find myself rewriting the code because I found a better idea


Now of course.. no one is perfect, so I shouldn't speak in absolutes because we will always find outrselves forgetting or messing up important aspects of the design


Point is- Perfect the Design, and you'll never touch the code again...


Just like the UNIX System and it's utilities- they've only been modified to add new features, but te core of the design has been untouched for just about forever

Ah I love this discussion... my first 2-page thread :D



Woot Woot! That is like a little present for my Turkey-Day-Birthday today. Woot Woot.



All you guys on linuxquestons.org are just plain awsome

Mr_Munkey 11-24-2005 03:53 PM

Quote:

Originally posted by TGWDNGHN
When I work on a project... the last thing I ever think about is the actual language or implementation.

I always start with the logic- "hmm... what is the most logicial way to systematically solve this problem or perform this function?"


All the planning would involve balancing speed with efficiency. Even in these days that we have lots of RAM storage... once you become a C programmer you still can't help but strangle your program of every byte you can spare. Now depending on the program this can be good or bad. For example: if you are using a Bubble Sort (I don't see why yu' ever use one though), then one byte of storage would determine whether it would continue running even though the array is sorted, or just exit. You really need to think about whether it is actually worth it.



The beauty in a program comes from a design... if it is flawed- then there is no use on trying to perfect the code for imperfect logic. That is why I never rewrite code. Yes, I'll implement new functions, yes- I might even replace a small section of the design for one better suited for a different situation- but I never find myself rewriting the code because I found a better idea


Now of course.. no one is perfect, so I shouldn't speak in absolutes because we will always find outrselves forgetting or messing up important aspects of the design


Point is- Perfect the Design, and you'll never touch the code again...

Well put! :)

That is more along the lines of what I was thinking. Since I'm fairly new to programming, I'll learn new techniques to do different things from time to time, which I then come back and might re-write something to make it that much better. The design and function really stay the same, it just gets better and more stable.

TGWDNGHN 11-24-2005 07:10 PM

Some things are mathematically complex... trying to find the idea algorithm, for example, is a biggie.


The shell sort, for example, works great except when it comes to numbers that are powers of 2- for mathematically complex reasons. Now the design might call for something to be sorted, but the design should never specify the sort to be used (unless, of course, you have a program that tests and compares different sorts... or if you are in a programming class and you MUST use a specified sort)


For example: never assume that your input and output consist of the keyboard and screen- always make room for it to, for example, be redirected to a file


This is why Standard Streams are good. If we had some proprietary measures on performing I/O (ex: Keyboard, screen, filesystem-specific file I/O, etc.) then we would have to rewrite a program for every possible situation and environment that it could be used in...

Or you could package it with loads of drivers and stuff, but that defeats the holy UNIX Principals. Te reason why UNIX is the perfect Operating System is because it is perfect by design... the beauty lies in that you can easily replace any of it's modular components and get them to work


Driver programs happen to be even better- because if you don't like the design of the driver then you can just use it to call up another one (Ex: bash shell into ksh/csh/tcsh/zsh/etc.)

alred 11-25-2005 04:11 AM

precisely !!

nice to hear people bringing up the unix principle in design ...

its pretty true that *nix are built with perfection in mind although i couldnt totally understand that completely but i just knew it :jawa: ... and in the context of free software , let us forget about all those non-sensical zealots super-intelligent opinions of they themselves , i think the only truely revolutionary and outstanding idea behind it is that with free software everybody could read , glance and use(let us also forget about the legal implications down here) the codes , something quite unheard of , not even among those published true freeware(cause sometimes we still need to pay for the source)...

revolutionary as in as if we are actually able to see women sharing and exchanging their best and self-invented cooking recipes with other women strangers that they dont know wholeheatedly :D (ever seen women "pulling each other hair"??) ... what i mean is ... sometimes its really fun helping people in answering their coding problems by stepping through system source codes , we will almost always find something interesting and unexpected and never stop learning just about everything(well ... its also depending on your age , whether you are young enough to be able to do that )


QUOTE :: by TGWDNGHN
"Ah I love this discussion... my first 2-page thread :D "

yup ... why not ... view count had just sky-rocketed more than 330 , let us flood this thread


ok ... just kidding ... seriously ...
theres a guru in this forum once said that we can either code from the top or from the bottom but never never start coding from the middle !! and i think its very true , at least try our best not to do that ...


*nough said !! if not ... those 0 replies might just as well open their eyes(and their mouth too!!) wondering what the hell those people are doing ... chit-chat chit-chat all the way like nobody else buisness ... something like this ------> :eek:


enjoy !!

.

xhi 11-25-2005 08:34 AM

Quote:

good point ... but to think about it ... its totally possible to create better quality music when we are kind of drunk , but how about amature(professional??) coding ... sometimes i heard people saying that hackers/programmers all love music and sometimes influence by it(either classical or rock) and some of them might be pretty good musicians too ... Go with the flow ^_^
hmmm. being influenced by the product of someone elses drunkenness.... interesting. as far as coding better when drunk, no. not me anyhow. and for that matter not high either, on anything. im a far better sober coder, as hard as that is to admit to myself. :) maybe i do start coding better after 3 or 4 beers sure, but i can never stop at that point....

TGWDNGHN 11-25-2005 06:15 PM

People would think that coding drunk might badly affect the code... I disagree


After all, we can all completely @#$% up our programs or computers simply by TRYING to use pointers correctly... :D


Some of you all might have heard the old joke... The Engineer, Artist, and Programmer debating over what was Gods occupation. The Enginneer argued that god was an Engineer because of the perfection and architectures of all the designs he had created... the artist spoke of the beauty of the life god created, alluding to the same perfection as the enginneer. Then the programmers speaks up screaming "BUT WHERE DO YOU THINK HELL CAME FROM?!"


Of course... he was not speaking of perfection, he was alluding to pointers. Or maybe assembly language?



Thats why I love programming, its so much fun :D!


Besides... most programmers are either lightly-carelessly(not) religious or atheists (like me :D)


Either way, you gotta admit the following:
1. (Especially in game programming,) when we program- we are god. As for out little programs, scripts (, and game NPCs/ characters)- they do as we command
2. Out programs evolve in a fashion strikingly similar to what Darwin had proposed. As a matter of fact- biologists an programms study the evolution between real and computer virus to trace out their similarities



oh yeah, talking about computers, right.


um...


Linux rocks, yeah, lets continue from there :P

xhi 11-25-2005 06:21 PM

>> Of course... he was not speaking of perfection, he was alluding to pointers. Or maybe assembly language?

I must disagree here. As assembly language is the language of gods. No joke, if you read the back of the bible it clearly says that god wrote us in assembler. Of course it is AT&T that he used not Intel :) ..

And what do you have against pointers?

TGWDNGHN 11-25-2005 06:38 PM

Ha ha I'm sorry I gave the wrong impression, I actually love pointers. I understand them, and make use of them like crazy and I normally dont have a problem. I was wriitng sarcastically as a joke... I happen to know quite a large number of people far and near who cant work out pointers for a can of beans.


As for Assembly- same deal. I learn assembly on the side, and being that all my planning takes all low level aspexts into consideration, I don't even needto change my design to accomodate an Assembly Implementation. I mean heck... I think in binary all the time! no joke, I use binary math for practical purposes, really useful.


So if you didn't feel like reading all that:
1. I love pointers
2. I love assembly
3. I was writing jokingly

yup yup yuppers




Even in Java, a language as pathetic as Java- my peers have problems handling it's references... its so pathetic! How can you get it wrong on something as pathetically pathetic as Java?


Oh well... none of them really care for programming, or think like a programmer. Most of them just cheat and are planning to drop out anyways. But even for those who cares, the little noobies people like to poke every now and then for fun, its amusing to watch them suffer


But its part of growing up and becomming one with the Tao... becomming one with the Foo.... becomming one with the Machine.


After all, we all went through are larval stages, and their time will come too

BrianK 11-25-2005 10:48 PM

I'll chime in and say that the last thing you want to do is start coding (assuming the project you're working on is of a decent size and/or function). When I design a program properly, the very last thing I do is code. If the design was done properly, coding isn't much more than typing.

I typically write "requirements" from the user side - what the person using it will want it to do and how they will ask it to do it. From that, I write requirements from the system side - how the system will do what the user requires. Then I'l do some flow charts to see how the data is moving to make sure I'm not moving around more stuff than is necessary, then some UML for the objects and such that will be used.

Once all that is refined & I'm satisfied, I start writing code. I start with the very basic bits first - I want something that runs right away so I can start testing. I write as much testing code as program code & run tests at every new revision to ensure that the new stuff hasn't broken any of the old stuff.

It sounds pretty academic, but after having done several large projects the with the "sit down and start going" method, I can tell you that that method almost always ends up taking longer because you will inevitably have to adapt your code to make it do something you hadn't planned on doing.

TGWDNGHN 11-26-2005 05:24 PM

Yeah, large projects always require that it it's functionality from the user and programmer's perspective be planned out. Otherwise... we forget stuff! I mean, we're only so human


If we know what we want, then often we can either "remember" or otherwise improvise... because it wouldn't be so important, but if you do some sort of professional or commercial project... yeah, more time goes into planning than coding!

alred 11-27-2005 10:04 PM

yup ... also dont forget about what someone had said earlier ::
"It depends how big the program is. If it's small enough to keep all the design in memory, I just write it. If it's bigger, I draw module structure and then start the most interesting one. Oh... and if it's GUI, I draw GUI first."

i guess we will be surprise at how much time some(most of them ??) of those those "real-world" bigger projects have "wasted" on just the user-interface which is the GUI , some people call them the WIMP of computer applications , namely the Windows , Icons , Menus and Pointers ... i guess probably with our GUI inplaced but without the actual codes pretty much resemble suspending widgets waiting for "modular connections"(the correct words?? dont get me wrong , i just knew it although i'm dont quite understand it completely about what i'm trying to say) , and thats could probably help us in sketching up a "flow" of the application or re-improvising that "flow" if we already got a previously planned one ...

to think about it ... having said the above ... i think choosing the "correct" language in the first place is also very important in this case ...


QUOTE :: by TGWDNGHN
"Linux rocks, yeah, lets continue from there :P"

not necessary must be that i guess , we still have our bsd and open solaris and we can also look at their codes and documentations too , even just for the fun ... i think anything that can play music and rocks are also good if they also releashed their source in one way or another ...

QUOTE :: by TGWDNGHN
"But its part of growing up and becomming one with the Tao... becomming one with the Foo.... becomming one with the Machine."

thats really great if you could come to terms with that kind of understanding but we might have problem having sex with our loves one cause doing it with a "machine" is so horrible and un-creactive plus un-inventing too ... "arrrrrrgh ... with you things are forever bits and bytes , bolts and nuts , sooooo boooooring !!!!" :D


.

TGWDNGHN 11-28-2005 03:10 PM

Oh and when I said "Linux Rocks", I wasn't so much advocating it as I was trying to move along the subject. I WOULD prefer to use a nice UNIX system, but it is much easier to use Linux due to all the programs, documentation, help, ect. available.


Oh and...Aw come on now, don't be hating! If you want to make your sex life more interested, try encrypting yourself using a little fancy stuff like xor and compression and stuff, and maybe your lover and figure you out


After all, they don't just say "you're so complicated" for nothing :P

alred 11-29-2005 01:35 AM

hmm ... probably i'm too fast in jumping to conclusion with your previous posting :jawa:

>> After all, they don't just say "you're so complicated" for nothing :P

you are not bad at all !!


seems that theres a live cd for LFS ... and to speak the truth ... until now i never try out any of the live CDs out there , i think later on i will probably give LFS a go ... :)

TGWDNGHN 11-29-2005 08:14 PM

DO IT DO IT DO IT DO IT!!!


YOU WILL NOT REGRET IT!

I personally ordered my live cd... it cost I think about $1.95 but the shiiping cost somewhere around $1.50 :rolleyes:

But believe me... it's worth it. I printed out the book, nice and highlighted- followed along... easy. Just a word of advice: COPY AND PASTE TO PREVENT TYPING MISTAKES


unless you wanna do it 20+ times like I did :study:


All times are GMT -5. The time now is 10:46 AM.