Code monkey

debonair

Well-Known Member
Joined
Sep 10, 2008
Messages
228
Reaction score
2
Location
Cape Town
Any advice for a self taught developer who wants to learn good programming methods and practices? My boss often calls me a code monkey, because, though my code works, its not exactly what you would describe as elegant.

I want to write code that makes sense to everyone, not just to me.

thx!
 
Without seeing a sample of your coding style, I can't suggest anything except for the following:

- Good comments will help more than anything in making your code easier to read.
- Try to write your code as simply as possible, don't use too many "clever" tricks or shortcuts that will confuse others.
- Get your code reviewed - either once you've finished a unit of work, or (preferably) while you're writing it. I've found that a few sessions of pair programming with "wayward" coders does a lot to get them back on the "straight and narrow" as it were.

BTW, being a code monkey isn't necessarily a bad thing - writing code that works, and allows you to ship your product on time, is way more important than "pretty" code - but that doesn't excuse you for writing code that no-one except you can maintain, which (IMO) is the greatest sin a programmer can commit.
 
(re-iterate The_Assimilator +1)

Comment comment comment comment comment.

I've seen crap like "The database open function" <-- doesn't mean **** to anyone. "Opens the database and is used everywhere else as a central point to help in fast deployment and maintenance of code by changing 1 file/database string"

KISS... no not your girlfriend (or dude-friend)... the simpler the code the better. You don't want 3894263490 include files in 1 directory called /includes/ and then have your home page just reference 6 includes and each of those includes reference an include. Not ****ing needed and over complicates ****. Same with how you write code everywhere else.

Choose a directory structure and stick with it, I have:

_lib
---css
---db (holds my connection string info and/or modules for database layer)
---common files/functions like jquery.js etc
images

If your app has many modules (users/suppliers etc) split those up in directories listed in a "modules" section as well. Keeps it clean, readable just by looking at the directory structure and can get any other programmer into your code and knowing what to do/where to go by just looking at the directory structure and how it's put together.

Naming convention of your files is also important to go with the above. Rather split the files up into smaller parts if they do different things and calling them nice names... add_User.php says a whole lot more than users.php or userfunctions.php

If you don't have someone to review your code, try and read up on the subject. Try to make things as simple as possible to implement, create the stuff and go "Okay, how do I make this faster/more efficient" (get tools that shows execution times etc). Mostly, just try and keep an open head to what you're doing and how you'd like to receive a project that is half done (or completed) and have to then make changes to it.

Oh, and learn basic database design fundamentals. What a relational database is, what normalization does and how to implement that from a basic client specification. <-- this is probably the most important thing you'll ever do, because it's like building a house with a crappy foundation. If your foundation isn't properly laid, your house will fall in on itself and no amount of duct tape (code) will save it from itself.
 
Without seeing a sample of your coding style, I can't suggest anything except for the following:

- Good comments will help more than anything in making your code easier to read.
- Try to write your code as simply as possible, don't use too many "clever" tricks or shortcuts that will confuse others.
- Get your code reviewed - either once you've finished a unit of work, or (preferably) while you're writing it. I've found that a few sessions of pair programming with "wayward" coders does a lot to get them back on the "straight and narrow" as it were.

BTW, being a code monkey isn't necessarily a bad thing - writing code that works, and allows you to ship your product on time, is way more important than "pretty" code - but that doesn't excuse you for writing code that no-one except you can maintain, which (IMO) is the greatest sin a programmer can commit.

I definitely agree with the latter two points. The first however is where i somewhat disagree.

Comments are great but code that talks to you is 10x better. When i read code, i want to read the code not the comments. The comments can supplement info about the code but code itself should reveal its intent and what exactly is going on. If the comments however are the only thing that says what the code is about, you are not doing it write. I have personally seen code which had more comments than code!!! While i will concede that the comments were really concise and relevant (in this case) the overall readability of the code what shyt.

There are several great blogs posts about this (the links escape me at the moment), but I would suggest downloading Martin Fowlers presentation from NDC2009 about clean functions as a start.

If you writing comments along the lines of "increment i by one" - arrggrrrrrrh... simply put WTF
 
I definitely agree with the latter two points. The first however is where i somewhat disagree.

Comments are great but code that talks to you is 10x better. When i read code, i want to read the code not the comments. The comments can supplement info about the code but code itself should reveal its intent and what exactly is going on. If the comments however are the only thing that says what the code is about, you are not doing it write. I have personally seen code which had more comments than code!!! While i will concede that the comments were really concise and relevant (in this case) the overall readability of the code what shyt.

There are several great blogs posts about this (the links escape me at the moment), but I would suggest downloading Martin Fowlers presentation from NDC2009 about clean functions as a start.

If you writing comments along the lines of "increment i by one" - arrggrrrrrrh... simply put WTF

In everything there should be a balance, you obviously have had the same experience as I where there's either a ton of comments but no real structure to the code making you go "WTF" or a ton of readable code but no comments in that actually explains where it's implemented and why.

If your code is simple enough to read and be understood by anyone, combined with a directory structure and naming convention of any files involved, you don't really need comments. But not everyone has the same style of programming, for example, I'd do the following in VBScript:

Dim weight : weight = 0
If weight <> "" Then
'Do some **** yo
Else
'Nothing, somehow the weight variable didn't get set?
End If

Where-as others would go

Dim weight
weight = 0

If NOT weight = "" Then
'Do some **** yo
Else
'Nothing, somehow the weight variable didn't get set?
End If

The last example is how NOT to do things (why use a double negative to do the same as the first one in less code and a better understanding when you read it?) anyway... I think we all agree on the fundamentals :p
 
Any advice for a self taught developer who wants to learn good programming methods and practices? My boss often calls me a code monkey, because, though my code works, its not exactly what you would describe as elegant.

I want to write code that makes sense to everyone, not just to me.

thx!
To me, that is a good sign of a person who has the mindset of developer and not a code-monkey.
There is more elegance in simplicity, however that not a license to do dumb ****.

To add to that - you yourself want to be able to read your own code 6 months from now and know exactly what is happening
 
ton of readable code but no comments in that actually explains where it's implemented and why.

Actually i have seen code with no comments, but was fully comprehendable, understandable etc etc and gave me a warm fuzzy feeling :)

Coding style is another topic all together. However, I think that bad coding styles become prevalent when there is no check or review in place. Considering the OP, I think that he may have bit of difficulty on getting his code reviewed.

Be willing to learn - you think you know alot about something - YOU DONT!! Plain and simple. For everything you think you know there are 10 things you dont. So accept that and accept the critics (yes, it will make you feel like krap at the moment) but the benefits far out way those five minutes of self pity.

Read, Read and read some more - there thousands of quality blogs out there which by simply reading makes you better.

Practice makes perfect and nobody is perfect, so why practice - if you agree with this, you have are screwed in your job and life. Yes, no one is prefect but there are definitely those who are better and only get that way by practicing :)
 
<offtopic>
In recent time i have started to cringe every time someone links to Joel Spolsky or Jeff Atwood blog post as a reference. Yes they do have some good applies-to-every-developer type posts but to me, it seems that most people are very comfortable with accepting what they say at face value rather than actually thinking about the issue for themselves and coming up with their own opinion.
</offtopic>
 
Comments are great but code that talks to you is 10x better.
+1

I guess the problem comes where you or someone else has to work on the code.

I'll tell you what problems I've come across bcos of code monkeys(not that I'm not one)
-Lots of undeleted code that is unused
-Hard to understand code(understanding logic/purpose of code is hard)
-Unsimplified code due to being copied and pasted various times.

I think the problem of Code Monkeys is when there is a tight deadline to deliver, sometimes I'd see swear words in the code(which should be normal when the receptionist got paid more than the programmer:confused:)
 
Getting a book like this should help you a great deal getting your patterns right. IMO a good developer writes good code and uses good patterns. Even bad code in a good pattern is better than good code in a completely useless pattern.
 
I want to write code that makes sense to everyone, not just to me.
That is a fabulous attitude, and a good one for a developer. You're already ahead of most of the pack... now read, read, read! Microsoft has their own list of best practices if you are into the Windows/.Net thing, and there are plenty of other BP docs out there (no, not the oil company :D). Take time to decide what works best for you, and stick to it. Consistency is a big plus when working with someone else's code.
 
i use codeignitor for plenty of projects, and i use their style guide to code. Maybe it might help you too.

Hmmmm, interesting. I think I do just about everything differently. I don't really like this inconsistency for one.

Code:
INCORRECT
if ($foo AND $bar)
if ($foo || $bar)

CORRECT
if ($foo && $bar)
if ($foo OR $bar)
 
Hmmmm, interesting. I think I do just about everything differently. I don't really like this inconsistency for one.

Code:
INCORRECT
if ($foo AND $bar)
if ($foo || $bar)

CORRECT
if ($foo && $bar)
if ($foo OR $bar)

the reason for every style is given, as per the example, this is given.

Use of || is discouraged as its clarity on some output devices is low (looking like the number 11 for instance). && is preferred over AND but either are acceptable, and a space should always precede and follow !.

also it must be said that its more of guidelines than set rules :)
 
Steal lots of code online, then you don't have to write any of your own...

I do that alot, but, all jokes aside, it does help you to see what other people are doing. Download some projects from sourceforge for instance, and get ideas on their coding styles... Also, there are TONS of free books. Go to www.google.com/linux and search for c++ books (if you're into c++), you'll find lots.

Here is a link to quite a number of good, free books.. You can buy these books from amazon / loot.co.za, etc, but the author is kind enough to allow you to download them..
http://www.mindviewinc.com/Index.php
 
Steal lots of code online, then you don't have to write any of your own...

I do that alot, but, all jokes aside, it does help you to see what other people are doing. Download some projects from sourceforge for instance, and get ideas on their coding styles... Also, there are TONS of free books. Go to www.google.com/linux and search for c++ books (if you're into c++), you'll find lots.

Here is a link to quite a number of good, free books.. You can buy these books from amazon / loot.co.za, etc, but the author is kind enough to allow you to download them..
http://www.mindviewinc.com/Index.php
 
I think you guys missed the point ... or I did.. but being a code monkey dones not have much to do with coding style. but more to do with problem solving and the studying of patterns like the gang of 4 and the like
 
Top
Sign up to the MyBroadband newsletter
X