Is this normal for coders?

Contribute code to SolydXK and make it even better.
Deleted User 2764

Is this normal for coders?

Postby Deleted User 2764 » 06 Mar 2014 03:43

I have to ask... And I hope this is in the right area...

I had been working on a project in PHP for a few months now. And it seems I find things are broken and got confused at how I coded things so I end up starting over and re-writing it as I think of better ways to code it. :roll:

Well, tonight, I had been working on that same darn project and re-writing again. This time I think I re-wrote this one portion of the code at least twice and it still didn't work! So I tried a different approach (which I wish I had thought of MUCH sooner) and it worked! It was a long day. LOL!

What takes so long is when things look like they should work. There appears absolutely no reason at all why it does not work. Yet it does not work.

Is this normal for coders to go through - where they would take months to get something to work and end up re-writing the entire code several times?

Or am I just in need of more practice and skills?

This project luckily does not have a deadline. But if it did, I think I'd be screwed! :?

User avatar
Arjen Balfoort
Site Admin
Posts: 9223
Joined: 26 Jan 2013 19:36
Location: Netherlands
Contact:

Re: Is this normal for coders?

Postby Arjen Balfoort » 06 Mar 2014 07:39

I have been coding for at least 17 years now, and rewriting large parts of a project, or sometimes just beginning from scratch is not uncommon. However, in a commercial context this hardly ever happens, especially when you're working in a team on the same project. Teams need to work in a standardized manner, which often gives fast results, but coders do miss the satisfaction of making something "beautiful", and maintaining existing code often makes it worse, resulting in what I call "spaghetti code".

Now that I am my own team, and time is not a commercial factor. I come across those moments more often that I need to rewrite software. Sometimes because performance is inadequate, or I have trouble maintaining somebody else's code (old Mint applications), but mostly because business processes change, and the supporting software doe not have the needed features.

So, yes, rewriting code is very common. Things change, you learn while you code, you knew what you wanted, but you did not think through what you needed before you started the project. There are many reasons that forces developers to start all over again (or wanting to).


SolydXK needs you!
Development | Testing | Translations

User avatar
ScottQuier
Posts: 1781
Joined: 18 Jul 2013 15:55
Location: Newport News, VA

Re: Is this normal for coders?

Postby ScottQuier » 06 Mar 2014 12:13

I've been a coder since 1977. When I started out I had that same sort of experience. There are some things that a coder can do to reduce the re-work:
  • Develop a standard way of doing "things". There are some things that need to be done in one project that are repeated in another. Write it once and take your time about it and get it right. Then copy/paste this code from one project to the next. If you are working in an Object Orientent environment, you can reduce the amount of copy/paste. One can also create libraries of code and reference/link to these libraries as needed.
  • As you write the code, include lots of comments. Somethings to include in these in-line comments are what you are doing, the steps needed to get from "a" to "b", what the imputs to a function are and what are the expected outputs. Include narritive to describe the logic involved in some of the more essoteric code so that you don't have to decipher it at a later time.
  • Believe it or not, I still rely on flow-charts and other process diagrams to map out what the code will be doing and how to get it done.
  • Play computer - once you've written the code take paper and pencil and walk through the code, line by line. Keep track of the value of your variables. Make sure the code is behaving as designed.
  • Keep your code modular. Write in small, highly specific and focused functions. Generally speaking, if you have a function that has more than about 50 lines of code (not including white space and comments), you probably need to look at how you can break that function up into two or more.
  • Write a test harness for each function you write. This is a process commonly used by coders to ensure the function is behaving as designed.
  • Design test cases for your functions. Test cases should include at least three points; 2 valid end-points, and a valid middle point. The purpose of your function will define what these end-points are. As an example, imagine a funtion that tests the value of an imput parameter to determine if it's a natural number. Two end points would be (1) and some large number (1,234,343). A mid-point value might be 100. Good testing would also through in some obvious invalid parameter values. For example, -10 and the string "asdbd" should drive the function to return an indicator that input values are not natural numbers.
Even with all that engineering, I still encounter times when I end up re-writing sections of code. Not, usually, during the project development phase; usually it's a year or two down the line when the code has been in production for a while. I'm tasked with making modifications because business practices have changed or because the operational environment has changed or for some other reason. When I open up a section of code I'll discover that I've learned things since that code was last touched and, if I have time, I will update the code. I can usually justify it on the basis of performance (sometimes) but usually on the basis of better security or protection against invalid data or some such.

Any more, I seldom, if ever, throw out the entire code base and start over. There's usually a gem or two worth keeping. So, if I can get to the point where the code is good enough the first time around then, considering what little I have to work with ... well, never fear, you too will get to that point.

A final thought: A stitch in time saves nine. Taking your time in the planning/design stages of a project will more than pay for itself later.
Scott
Quoting zerozero, "The usage of PPA's in debian-based
systems is risky at best and entails serious compatibility
problems; usually it's the best way to destroy an install"

User avatar
Arjen Balfoort
Site Admin
Posts: 9223
Joined: 26 Jan 2013 19:36
Location: Netherlands
Contact:

Re: Is this normal for coders?

Postby Arjen Balfoort » 06 Mar 2014 13:33

What he says ^ :D


SolydXK needs you!
Development | Testing | Translations

Deleted User 2763

Re: Is this normal for coders?

Postby Deleted User 2763 » 06 Mar 2014 14:56

CVS is your friend. (If you haven't installed it in SolydXK yet)
It lets you make changes with abandon. You can always revert.

I also put my /etc/ configuration files there.

-Hinto

Deleted User 2764

Re: Is this normal for coders?

Postby Deleted User 2764 » 06 Mar 2014 15:13

@Schoelje - Thanks for the reassurance. :) At least I know some of it isn't just my lack of skills.

@Scott - I 2nd (or 3rd after Schelje) what you said! Everything!! :) In fact I do nearly everything you suggest except I think I outgrew the paper/pencil part back in 1980. :lol: :oops: As for flow charts, I don't know why but I found them more confusing. I usually type in comments what I want the portion of the code to do and then just code it in. And test the heck out of it and keep fixing things until it works. Maybe that's my problem.

The problem is, I been coding since 1980 (when I was 14 - now you know my age :oops: ) when my parents first got a TRS-80 Model III computer with cassette and 4K RAM and some programming books on Level II BASIC. I remember I would write things over and over at the kitchen table at supper time. Then go to the computer and try it and keep working at it.

That's the problem - I don't think in all those years (BASIC, C, C++, .NET, ASP, PHP, Perl, Python, Java, JavaScript, HTML, CSS, etc. etc.) I ever learned to really code properly, maybe? I mean, I even took a few programming courses (online via our local school district's continuing education). I sometimes wonder if I have the 'talent'. But yet it's so intreguing and I can't seem to keep away. Not only that, I got a really wonderful job I love that I do php/MySQL, web development and perl/server stuff (I run a LAMP server as well). And they like my work so I'm good there.

I know working in a team is a lot different than working alone. I think when I'm working alone I'm more critical where in a team I take on the "I do my task, they do theirs" thing. I do remember doing one site and that was when I was using Windows and I used a program called "Artisteer" to design the site. It actually was a personal site for someone on the team. Awhile later they edited it and it broke. I couldn't figure out how to fix it! It was so complicated so I recommended removing the artisteer junk from it. They did that and are keeping up the site just fine themselves. So much for my bright ideas. :roll:

I code sites by hand normally but using Artisteer was kinda a neat, quick way to get nice features fast. But at a price of complicated code.

I'm one of those who hates hacking things together so it "just works" and leaving it at that. I too have found over the years that I learn things and that's when I rewrite things to be better.

Also, I am using jCodeCollector 2.5 to collect snippets. This way I have something handy to look at to see how I did something in the past. When I do a project now, after it's working good I go back and copy out the good parts and store them in the snippets collector for if I need something like it again.

I also use Eclipse as a development platform. I think some can tell by another thread that I absolutely love Eclipse! But I have in the past used simple text editors to code (no syntax highlighting, etc.).

I think you guys are right - I have to find a good method to use for coding that is more efficient. I need to really think things out more before I start writing actual code. I been just coding what is coming out of my head (ie. Head-to-Code? :lol: ) and probably that's where I'm confusing things.

Deleted User 2764

Re: Is this normal for coders?

Postby Deleted User 2764 » 06 Mar 2014 15:17

@hinto - Thanks but I don't want to have to run too many servers on my machine. I run a ton of them as it is. Ok, ok, that's and excuse. The real reason is that I can't run CVS on this project because I have to have the files in a certain place and they are served via Apache server (it's a php project). And I find CVS confusing to use so I usually avoid using these things. I know I have to sometime learn to use those types of things (what is the most common now? git is it? SVN? CVS?) I don't know anything about these things (as you can tell) outside of one time I set up an SVN server and used a script someone wrote to do the SVN part. That was it. Oh yeah, I forgot - I had used SVN on SourceForge for a robotics project but it quickly confused me. :roll:

I think I'll work on getting my coding method right. Then work on learning versioning.

Deleted User 2763

Re: Is this normal for coders?

Postby Deleted User 2763 » 06 Mar 2014 15:21

Not arguing with your methods. but
CVS is lightweight.
Often you'll end up making your own backups of files/directories without a source control (using some home-brew convention), but in the long run that will cause you more pain than just biting the bullet and installing one locally.
It's not hard.
The knowledge that you can always revert is light tightrope walking with a net.

-Hinto

Deleted User 2764

Re: Is this normal for coders?

Postby Deleted User 2764 » 06 Mar 2014 15:28

I'll look into learning it when I have more time. Thanks for the suggestion. Right now I want to get this one project out of the way before I take time out to learn things. It might not be hard for some but usually those things take me awhile to learn.

User avatar
ScottQuier
Posts: 1781
Joined: 18 Jul 2013 15:55
Location: Newport News, VA

Re: Is this normal for coders?

Postby ScottQuier » 06 Mar 2014 15:31

RavenLX wrote: @Scott - I 2nd (or 3rd after Schelje) what you said! Everything!! :) In fact I do nearly everything you suggest except I think I outgrew the paper/pencil part back in 1980. :lol: :oops: As for flow charts, I don't know why but I found them more confusing. I usually type in comments what I want the portion of the code to do and then just code it in. And test the heck out of it and keep fixing things until it works. Maybe that's my problem.
You just think you outgrew paper/pencil and flow charts, etc. There's a reason it's called software engineering - process is king! As for your last sentence above, testing is good but the testing will take a lot less time if you first spend some time on the planning/design/engineering
RavenLX wrote: That's the problem - I don't think in all those years (BASIC, C, C++, .NET, ASP, PHP, Perl, Python, Java, JavaScript, HTML, CSS, etc. etc.) I ever learned to really code properly, maybe? I mean, I even took a few programming courses (online via our local school district's continuing education). I sometimes wonder if I have the 'talent'. But yet it's so intreguing and I can't seem to keep away. Not only that, I got a really wonderful job I love that I do php/MySQL, web development and perl/server stuff (I run a LAMP server as well). And they like my work so I'm good there.
See my comments above about engineering. Taking language/programming courses is a very good start. Now, just apply structure and process. Something to keep in mind about process - if it's not repeatable it's not really a process. You should be able to do things a certain way on one project then move to another and use exactly the same steps on the second - after taking into account the impact of project size, etc.
RavenLX wrote:I think you guys are right - I have to find a good method to use for coding that is more efficient. I need to really think things out more before I start writing actual code. I been just coding what is coming out of my head (ie. Head-to-Code? :lol: ) and probably that's where I'm confusing things.
I believe you have a handle on about 1/2 the issue. The other one is the version control that hinto mentioned. Coding without version control is coding without a safety net - one slip and you'll fall off the wire and really be in a bad way.

Oh man -- hinto beat me to the punch with the tightrope analogy! :lol: ;)
Scott
Quoting zerozero, "The usage of PPA's in debian-based
systems is risky at best and entails serious compatibility
problems; usually it's the best way to destroy an install"

Deleted User 2763

Re: Is this normal for coders?

Postby Deleted User 2763 » 06 Mar 2014 15:33

I started professionally coding C/C++ in 1990 with Window 3.0 with no *nix experience. (even in College it was Pascal)
In 2006 (and a few other languages), I started using Linux due to 64 bit int* problems that didn't surface until
testers ran it on AIX.
I made the switch and didn't look back (tho I do code on a Win7 VM using Visual Studio)
FWIW, the switch to Linux was easy not because of anything I did, rather ease of installation and the support of community forums.
-Hinto

Deleted User 2764

Re: Is this normal for coders?

Postby Deleted User 2764 » 06 Mar 2014 16:05

ScottQuier wrote:You just think you outgrew paper/pencil and flow charts, etc.
Actually, the real reason is writing on pencil/paper is very painful for my hands, which is why I have to do everything on the computer. And I get too confused writing and trying to "play computer" because 99% of the time what *I* think is definitely NOT what the computer actually does. It just takes too long. Seeing the computer actually run the code and watching what happens to the variables, etc. is much faster for me and I understand it far easier.
ScottQuier wrote:testing is good but the testing will take a lot less time if you first spend some time on the planning/design/engineering
That I agree with you 100%!! I will be doing more of that even per code portion as well, so that even each part/function has it's own plan.

[quotde="ScottQuier"]See my comments above about engineering. Taking language/programming courses is a very good start. Now, just apply structure and process. Something to keep in mind about process - if it's not repeatable it's not really a process. You should be able to do things a certain way on one project then move to another and use exactly the same steps on the second - after taking into account the impact of project size, etc.[/quote]I took a course in C++ (got 100% on the finals) and also in VisualBasic.NET with Database. Guess what? They did have some overview on "brainstorming" but I forgot completely if there was a discussion of flow charts! See how easy I forget things! :roll: I think the VB.NET course went over it.
ScottQuier wrote:I believe you have a handle on about 1/2 the issue. The other one is the version control that hinto mentioned. Coding without version control is coding without a safety net - one slip and you'll fall off the wire and really be in a bad way.
Version control completely confuses me. I don't know anything about it. I don't want to have to guess what I'm working on if it's the current code or some old code and where is that old code? What if I don't want all of it "reverted", but only need to look up a portion of it? I don't want to run and find the code won't work only to find out I been running the wrong (old) version while making changes to a newer version (or vise versa) and spending hours, days, or months before I figure that out! And right now, I don't want to add something to an already-started project and confuse myself to the point where I can't finish this. Now is not the time for me to learn or install something that will affect the project. I just don't have that time.

I will probably add the CVS or SVN or whatever (still don't know what to use) stuff on my machine after I finish this project and before I start my next one. That way I don't get confused with what I'm already doing. I am expecting to finish my current project this month sometime.

Deleted User 2763

Re: Is this normal for coders?

Postby Deleted User 2763 » 06 Mar 2014 16:24

You revert changes. They are as big or little as your commits. There are also diffs (highly useful).
They are retained until you remove them.
What happens is when you commit a file for the first time, the server inserts the file. Diffs are submitted after that.
When you get "current", the server starts with the original an applies the diffs you have committed so far.
You can get by date, tag, etc, or just current. You can also revert back to a revision.
You can even get back a file you have deleted.
-Hinto

Deleted User 2764

Re: Is this normal for coders?

Postby Deleted User 2764 » 06 Mar 2014 17:37

Sounds complicated and a ton of files that I don't want to have to deal with backing up. See, whenever I'm done for the day, I zip up (with password) the project and save it on my backup media and cloud storage for safe keeping. I guess I could find a cloud storage for SVN or CVS but that's more complications than I'm willing to go into for just my own personal projects. I really don't want a ton of "diff files" laying around and not know what is what. I'm very strict as to how my files are organized.

I don't know. CVS may be great for teams of programmers, but for someone like me who rather keep things neat and organized, I can just go look at my backup of the file or old copy with KDiff to see the differences. I never do that though and never need to. Too much confusion. I just copy/paste the old parts into the new code as commented blocks and then it's right there where I need it. I can then step through and work on it.

I'll try CVS on my next project but I am not so sure I'll like it and may decide to go back to the old ways of organizing my files. Or I might think that CVS is the best thing since sliced bread.

I can't tell by what people describe. I'd have to see it actually working and use it for myself to really know for sure. I hope it's not one of those tons-of-backup-files-laying-around type things. I hate that.

Deleted User 2763

Re: Is this normal for coders?

Postby Deleted User 2763 » 06 Mar 2014 17:54

Dirt simple...
All that happens behind the scenes.

I can't make you adopt source control. However, it is a necessary piece in either 1 user or multi-user environment.
I'm going to bow out of this thread, but later, you can hear my echos of "I told you so" ;)

It's very similar to the adage, "You don't make a HD back up... Once"
-Hinto

Deleted User 2764

Re: Is this normal for coders?

Postby Deleted User 2764 » 06 Mar 2014 18:01

You can now say "I told you so" before I even try it. That way at least we can get that part of it out of the way. :lol:

I have it in my To Do list to install CVS when I start my next project. I hope it won't be the nightmare I'm dreading it will be!

Another analogy comes to mind (at least mine) : I can program a computer but I can't program a VCR! (I'm sure most in this forum will have heard that one before! :) )

User avatar
fleabus
Posts: 1227
Joined: 16 Sep 2013 04:24
Location: Winchester, VA USA

Re: Is this normal for coders?

Postby fleabus » 06 Mar 2014 19:04

I really have to hand it to you coders and developers. You folks really, always, amaze me. I've done a little bit of scripting but nothing like what you do.

For 30 years, being a more mechanically minded person, my job is/has been to make it go. I can program a vcr, or a mobile phone, cable box, build a computer, whatever. Gimme a gadget, I make it go.

Make this or that app version/OS version combo work with revision xx.x clapped out msi motherboard with revision x.xx buggy marvell sata chip or rev x.x network chip, or sound chip... Get that net going with rev x.x buggy intel network chip and Cisco x.xx... that kind of thing. Its broke! Get Dave, he'll make it go again!

I made it go, so the REAL work could get done. My hat is off to all of you. Without you we wouldn't have anything to run on our hardware.

I'm intensely sorry for the OT, but I had to say this.

Deleted User 2764

Re: Is this normal for coders?

Postby Deleted User 2764 » 06 Mar 2014 19:28

Don't be sorry! I have to give YOU hardware guys the hats off! I have dabbled in hardware in the old days too - and had built my own systems. I rather now just buy a laptop and if something goes, go to the local computer shop where the owner is like you - he makes things go again. 8-) Now days especially it's hard work as there are so many devices and things that go wrong and it's not like it used to be where you could sodler in a IC chip to get it running again. Now you pretty much have to tell the customer "You need a new phone because the motherboard is shot and it's old and the service will be upgrading to something it can't connect to in a month." How you guys manage to make these things go... it's a miracle! :geek:

I've always like to make "tools that make tools" in the old days. These days I'm doing mostly web development (which now days one can make whole applications that run in a browser) and for work that and LAMP server administration (along with setup, writing scripts for account management, etc.)

When I got my new cell phone last October - first Android phone ever, it took me some time to get used to it. Not a lot (since I already had an Android tablet) but it took a little breaking-in period to learn the differences between phone and tablet, how to make calls and receive them, getting used to no keypad, and a newer version of Android from what the tablet was able to run. Now my phone is stuffed with useful stuff (and fun stuff for those long waits) and I wouldn't be without it!

I'm also amazed at how much technology has advanced since the 80s (when I grew up). It's amazing! My current laptop far surpasses all I had dreamed of as my "dream computer" back then - and then some! And the best part is, it's running on Linux. :)

Sorry I am going off topic here too. But I think both sides (coders and hardware folks) working together is what brought us to where we are today.

Now if I could learn how to be a better coder - and keep up with what folks are doing today! :roll: :lol:

User avatar
fleabus
Posts: 1227
Joined: 16 Sep 2013 04:24
Location: Winchester, VA USA

Re: Is this normal for coders?

Postby fleabus » 06 Mar 2014 19:49

What's a LAMP server? Does that turn all the lights on when you walk in the door? :lol:

Mom says that was a top-secret government project back in '56 when I was born, but she drinks and does lots of drugs.

OK, shutting up now... :oops:

Deleted User 2764

Re: Is this normal for coders?

Postby Deleted User 2764 » 06 Mar 2014 20:33

fleabus wrote:What's a LAMP server? Does that turn all the lights on when you walk in the door? :lol:
Not quite. But if you want it to you might be able to get it to do that. :) LAMP stands for Linux, Apache, MySQL, PHP. Apache is a web server (most of the internet web pages are served by either Apache or Windows web servers, hopefully mostly Apache). MySQL is a database system and PHP, well, that's a scripting language (technically) but some say it's a programming language - I guess because it's pretty flexable and you can write some really great stuff with it. Like this forum. :) I wrote perl scripts to manage user accounts on the server (I work for a web hosting company). I also set the server up, and while it's pretty much self-healing and self running (99.9999% uptime), I am ready to jump in should something need attention, or if a customer needs help with something in their web site directory.
fleabus wrote:Mom says that was a top-secret government project back in '56 when I was born, but she drinks and does lots of drugs.\
Don't worry, you appear to have (hopefully) turned out ok after all. 8-) As A kid I loved robotics and space. I often wondered if I was an alien. Heck, some days I feel like I am! But who cares? It doesn't matter what our bodies are made up of as long as they work in some fashion that is at least tolerable. What matters is the mind.
fleabus wrote:OK, shutting up now... :oops:
I think I too better follow your lead on that one. :lol:


Return to “Code”

Who is online

Users browsing this forum: No registered users and 1 guest