Results 1 to 10 of 24

Thread: Article: Why Code Readability Matters

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Lightbulb Article: Why Code Readability Matters

    Have a read of this one guys. Since I work in another field (Avionics) that requires me to do more paperwork than actual hands-on work I can relate to this person's perspective on the matter. But I wonder if his approach is absolutely necessary the way he goes about it. What do you guys think?

    http://blog.ashodnakashian.com/2011/...e-readability/
    Jason McMillen
    Pascal Game Development
    Co-Founder





  2. #2
    I think the biggest thing I've learned in terms of readability is variable names. Having 1-3 character variable names that are used in multiple procedures or functions can get very confusing on first glance. I'm not quite sure about the multiple variable declarations in one line... it's readable enough if the variables have proper names IMO.

  3. #3
    Variable names (and ofcourse class/procedure/function names) are IMHO the most important thing to do right, because this is the only text you usually read apart from the comments. Using a load of comments to compensate for bad naming is just bad.

    Some things I also find important are the more subtle aspects of a coding style. For example, I find it annoying when someone writes his code using capitals everywhere (Especially for the reserved words: IF, BEGIN, ELSE). Because capitals are very attention-hungry, I tend to use them as least as possible. I think JAVA has pretty good conventions regarding case. They use lower camel case for variable/method names and upper camel case for classnames. Finally they use capitals for constants (were compound words are separated by underscores). I find this convention very nice, especially because allmost everyone uses it. I wish there was such a clear consensus within the pascal-world (Allthough I DO love the T, P and F prefixes, there is still quite a bit of freedom in using different case )
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  4. #4
    Egh, the only time I ever completely capitalize something is for a constant.

  5. #5
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25
    I find most will just copy-cat from the conventions used in examples. Makes sense. Just going with what another programmer of that language/script is doing since it seems to work.

    For example, I was originally taught to use i, j and k consecutively in my for loops. What sense does this make in practice? I have no idea, I just use them instead of say... a, b and c for example. Though this doesn't become a readability issue unless I'm trying to use the darn thing globally or something weird like that.
    Jason McMillen
    Pascal Game Development
    Co-Founder





  6. #6
    PGDCE Developer
    Join Date
    Jun 2010
    Location
    California, USA
    Posts
    25
    I understand the i for iteration or for index, I always that the j was just because it looked similar to i

    I stand on the more structured your code is the better off you are in the future. I look back at some of my code from 5 years ago and think to myself "Dang i sucked back then." mainly because I can hardly read the code. It is all cryptic and never used any standards for scope named variables or any prefix for the variable type.
    var
    strName : String;
    intCurIndex : Integer;
    chrDelimiter : Char;

    and etc. this is the convention I use for prefix, and if it is a class variable it is prefixed with an underscore _chrDelimiter or _blnRunning

    it just helps me to know what to expect the value should be. after all, it is all preference if you are working on your project "el solo" The compiler doesn't care as long as you haven't made a grave mistake and called the wrong function or have declared something in local scope that overrides global scope and have forgotten to reference the global scope with Self.VarName

    Well that is just my 2 cents.

    Oh and indentation. that is a big one for me. I must always indent consistently.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Comodo SSL