Programming style/habbits

How do YOU do it?

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

42 Replies - 5979 Views - Last Post: 05 April 2008 - 10:40 PM

#1 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Programming style/habbits

Post icon  Posted 19 March 2008 - 07:02 AM

I am often amazed when helping out in the forums. People seems to write entire programs out without testing as they go. In the C++ forum people will post long code listings riddled with syntax errors -- which makes it seem that they sat down and wrote this entire program without compiling once.

Me, I compile often. I also test often. I would say that probably about 10% of the code I write is purely for testing purposes and will not appear in the final product.

Now I realize that I am not a fast programmer and a good deal of that is probably related to the fact that I have a very conservative programming style (referring to how I work not my coding style). I am wondering if I am the norm or the exception. It would seem to me that other programmers are much faster -- and I think part of that has to be that they don't "waste" as much time writing code to ensure that the other code that they have written works.

How often do you compile the code you are working on?
How much do you test as you go?

Is This A Good Question/Topic? 0
  • +

Replies To: Programming style/habbits

#2 BenignDesign  Icon User is offline

  • holy shitin shishkebobs
  • member icon




Reputation: 6018
  • View blog
  • Posts: 10,444
  • Joined: 28-September 07

Re: Programming style/habbits

Posted 19 March 2008 - 07:10 AM

I design websites, so compiling isn't a big part of my day, but I test my code almost constantly. I usually have Notepad++ open with all the code related to the site I'm working on, the site itself up in Firefox and IE (and sometimes Opera and Netscape also), plus Gimp for quick image editing. After every 2 or 3 changes, I refresh everything just to make sure it's working the way I want. On the rare occasions I need to use a "real" language, I compile just as often.

Seems to me it saves time and energy in the long run to test functionality often rather than get to the end and lose hours trying to find a missed quotation mark.

I also usually have DIC open in my Firefox window... 1. for when I need a quick break, 2. for when I need a quick reference, and 3. for when I need to post a question. I must say I am so happy to have found this site - you all have saved my butt on more than one occasion. :D

This post has been edited by BenignDesign: 19 March 2008 - 07:14 AM

Was This Post Helpful? 0
  • +
  • -

#3 bflosabre91  Icon User is offline

  • go sabres

Reputation: 105
  • View blog
  • Posts: 1,439
  • Joined: 22-February 08

Re: Programming style/habbits

Posted 19 March 2008 - 07:25 AM

i test and compile like crazy. prob too much but i just want to be sure i dont break anything and typed everything correctly before i go too far deep. cause i hate backtracking what ive done..basically after i finish a new function or whatever it may be, ill test and compile. i dont really dig deep, but just make sure its functioning now, and then i do really specific testing later on in bigger chunks
Was This Post Helpful? 0
  • +
  • -

#4 girasquid  Icon User is offline

  • Barbarbar
  • member icon

Reputation: 108
  • View blog
  • Posts: 1,825
  • Joined: 03-October 06

Re: Programming style/habbits

Posted 19 March 2008 - 07:33 AM

View PostBenignDesign, on 19 Mar, 2008 - 07:10 AM, said:

After every 2 or 3 changes, I refresh everything just to make sure it's working the way I want.


I usually do this when I'm working on XHTML, using Firefox + Safari - in addition to that, my editor(Smultron) has an in-editor preview, so I can just push cmd+u to preview the HTML document.

For a language that actually needs compiling/testing, I'm usually doing a compile/test after any significant change, whatever that may be for the given project.
Was This Post Helpful? 0
  • +
  • -

#5 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Programming style/habbits

Posted 19 March 2008 - 07:44 AM

Another thing I tend to do that seems to irritate my boss (in that way where you can't tell someone they did wrong, but you wish they would have more sense) is that when I write a class I tend to write a complete class.

To explain what I mean by this I will give an example: In a recent POC (proof of concept) I had to write a class that would write auditing information to a database. Now the only requirement was that entries get written -- since it is a POC and not a solution the code was never expected to function past testing. BUT I went ahead and added other functions to update entries, to delete entries, to delete old entries etc. -- a complete auditing class. Nice to have, but now I have a class where only about 20-25% of the code was actually used/required.

I understand that sticking to the requirements document is important since "added functionality" leads to support problems later. But I can't help it, when I am building a class I tend to add in all the functions I think that Object needs.
Was This Post Helpful? 0
  • +
  • -

#6 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 180
  • View blog
  • Posts: 4,667
  • Joined: 26-November 04

Re: Programming style/habbits

Posted 19 March 2008 - 07:48 AM

I compile and casual-test frequently while writing code.
Initially when I started out, I used to test only when I wrote major chunks of code but it led to solid debugging sessions so now I compile as often as I can.
Was This Post Helpful? 0
  • +
  • -

#7 1lacca  Icon User is offline

  • code.rascal
  • member icon

Reputation: 44
  • View blog
  • Posts: 3,822
  • Joined: 11-August 05

Re: Programming style/habbits

Posted 19 March 2008 - 07:57 AM

I don't compile too often due to several factors:
- I am quite confident in my coding ;)
- every modern IDE does syntax highlighting so an obvious syntax error becomes visible right on the spot
- the applications I work on right now rebuild in a minute, and the initialization and startup takes at least twice as much time, so it is not that exciting (in the other room there is a monster, that rebuilds in 15 to 20 minutes)
- usually the test cases and functions I have to go through take even longer to test, so it is not really efficient to compile and test too frequently.

Anyway, this is why we like unit tests, don't we?

Back to your original question, I find it strange too, that people post codes full of syntax errors, because the compilers usually give quite good error messages recently (not like the javascript errors of IE), so they should not be too hard to fix.


However you can still read my answer as I compile and test as much as I can.
Was This Post Helpful? 0
  • +
  • -

#8 tody4me  Icon User is offline

  • Banned
  • member icon

Reputation: 12
  • View blog
  • Posts: 1,398
  • Joined: 12-April 06

Re: Programming style/habbits

Posted 19 March 2008 - 08:17 AM

I usually compile when I get finished with a portion of code. Sometimes there are errors, that I go back and fix. After the program compiles, I will do a basic test of the UI and make sure it's asking for the right things, then the actual testing is done by the users. If they should find something that doesn't work as expected, they'll let me know and I'll fix it.

This post has been edited by tody4me: 19 March 2008 - 08:17 AM

Was This Post Helpful? 0
  • +
  • -

#9 1lacca  Icon User is offline

  • code.rascal
  • member icon

Reputation: 44
  • View blog
  • Posts: 3,822
  • Joined: 11-August 05

Re: Programming style/habbits

Posted 19 March 2008 - 09:02 AM

View Posttody4me, on 19 Mar, 2008 - 04:17 PM, said:

... then the actual testing is done by the users. If they should find something that doesn't work as expected,

I would get a royal kick in the ass for that, lol!
Was This Post Helpful? 0
  • +
  • -

#10 Nykc  Icon User is offline

  • Gentleman of Leisure
  • member icon

Reputation: 726
  • View blog
  • Posts: 8,638
  • Joined: 14-September 07

Re: Programming style/habbits

Posted 19 March 2008 - 09:19 AM

I don't compile too often, but in web design my HTML Kit comes with a preview button. Also I constantly check my updates every few changes.
Was This Post Helpful? 0
  • +
  • -

#11 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Programming style/habbits

Posted 19 March 2008 - 11:23 AM

to be totally honest -- at work I use Java and develop in eclipse. Eclipse compiles the current file every time it is saved (and periodically while editing) so I don't really compile all that often in Java. I actually do not build and deploy the code very often. I write little "test programs" which test the classes, but since I work with an enterprise application I don't often test on the development environment until things are working on my laptop.


Quote

...the actual testing is done by the users. If they should find something that doesn't work as expected, they'll let me know and I'll fix it.
Well... um... that is *kinda* the way it works with me. The end users do tend to test the code (performance test/load tests/stress test (not really sure what the difference is between these), unit tests etc etc etc.) I really have no idea what they are doing... generally I get emails telling me everything worked, but the "business users" want to change one little thing (which generally means a big thing). Sometimes they complain because the code failed or runs too slow when a mere 4000 users were connected (this is often more of a hardware problem than my coding -- try explaining THAT though).
Was This Post Helpful? 0
  • +
  • -

#12 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Programming style/habbits

Posted 19 March 2008 - 11:40 AM

When writing software I use NUnit and do many unit tests, usually for every piece of functionality to ensure there aren't any errors before it goes to QA. At my last job I believe I was the only developer who actually did his own user testing before sending to QA.

Even in the C#/VB.Net forums I see people constantly posting code that, with a single look, you can see it wont work, and is normally the cause of their initial problem. When answering in the forums at times I'm guilty of writing solutions in Notepad, but for the most part I actually test the code I'm offering as a solution.

Even with the tutorials I write, the code is written in Visual Studio and tested before posting the tutorial.

Though I am very confident of my coding abilities, I will continue to do my unit tests and user testing just to ensure that I can catch as many of the errors as humanly possible before sending to QA. With the web application I'm currently working on I use my family for user testing as well, I tend to like to have non techies test my work when I think it's completed, as a programmer knows all too well how to find the "happy path", whereas end users will always find a bug if it exists.
Was This Post Helpful? 0
  • +
  • -

#13 Mikhail  Icon User is offline

  • Bastard Operator From Hell
  • member icon

Reputation: 58
  • View blog
  • Posts: 1,378
  • Joined: 26-October 07

Re: Programming style/habbits

Posted 19 March 2008 - 12:27 PM

When I am coding in C I compile almost every time when I make a new block of code, new classes etc, now when I am working with QBasic I only use it to help me for school in Math subject, I compile like crazy so I get accurate readings, now at my new job I have to save preview every few changes and also it is a policy to take a screenshot, when the program is done and to be submitted to QA, screenshot's go with it. All mistakes,errors everything is in the screenshot's it's a policy.
Was This Post Helpful? 0
  • +
  • -

#14 tody4me  Icon User is offline

  • Banned
  • member icon

Reputation: 12
  • View blog
  • Posts: 1,398
  • Joined: 12-April 06

Re: Programming style/habbits

Posted 19 March 2008 - 01:43 PM

View Post1lacca, on 19 Mar, 2008 - 11:02 AM, said:

View Posttody4me, on 19 Mar, 2008 - 04:17 PM, said:

... then the actual testing is done by the users. If they should find something that doesn't work as expected,

I would get a royal kick in the ass for that, lol!


I know, it's not the normal coding practice, nor is it a good one, but I'm also not in a normal programming role where specs are actually fully defined. Usually my specs are something like "can you try to give me this information from this table". To which I write a program to give reports, or lookups.

This post has been edited by tody4me: 19 March 2008 - 01:44 PM

Was This Post Helpful? 0
  • +
  • -

#15 spearfish  Icon User is offline

  • Monkey in Training
  • member icon

Reputation: 10
  • View blog
  • Posts: 746
  • Joined: 10-March 08

Re: Programming style/habbits

Posted 19 March 2008 - 01:46 PM

When I'm unsure about how to do something, I'll try a watered down example. Then I'll use that knowledge for the main script --- it may take 2-3 "mini scripts" to contribute to the main script, because I'm just learning so I'm unsure about a lot.

Then once I know how to do it, I'll write out the whole damn thing, all of it. That's when I mentally switch from "programming mode" to "debug" mode, and that's when I do my first upload.

For debugging I'll first scan for the obvious --- mismatched quotes, unclosed curly braces, missing semicolons --- really just the parse errors.

From there, I search for the more complex. Things like missing $ in variable names can trip a script up! I'll open up phpMyAdmin to see what all my script is doing. My codes generally have loads of "if" statements, maybe it's just habit, maybe they all are necessary. I comment out the redirects, and then put in "benchmarks" --- inside each if statement I'll throw in an echo of what it's doing and compare that to what's going on. Any parts giving me trouble I look at closely.

When debugging I shift my mindset, and then reupload after every little change, rather than almost never.

This post has been edited by spearfish: 19 March 2008 - 01:48 PM

Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3