Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Share Your Tricks for Satisfying Laziness in Your Programming

  1. Jan 8, 2016 #1
    People say the best programmers are 'lazy'. They don't like to waste time and they don't like to do monkey work. 'Lazy' programmers automate things, they use tools in wise ways to get things done easier and faster, they reuse code when appropriate, and they write code that's easy to modify, extend, debug, etc.

    If you're up to it, please share some tricks or tools that you use to support your laziness as a programmer.
     
  2. jcsd
  3. Jan 8, 2016 #2

    Borg

    User Avatar
    Science Advisor
    Gold Member

    Where did you get that?
     
  4. Jan 8, 2016 #3
    I'm not sure where the saying came from originally. I know that Larry Wall said, 'The three chief virtues of a programmer are: laziness, impatience, and hubris.'
    http://c2.com/cgi/wiki?LazinessImpatienceHubris


    Also on coding horror. http://blog.codinghorror.com/how-to-be-lazy-dumb-and-successful/

    It's really not meant to be taken literally. It's a humorous way of highlighting an important virtue for a programmer, which is to essentially to be smart about being efficient, to get more done for less work. For example, a lazy programmer might use regular expressions and other tools to make some modifications on dozens of large files, whereas the non-lazy programmer might go through each file and hand edit them.
     
    Last edited: Jan 8, 2016
  5. Jan 8, 2016 #4

    Borg

    User Avatar
    Science Advisor
    Gold Member

    A link or reference always helps - Laziness, Impatience Hubris.
    That kind of 'laziness' makes more sense in the programming world. I really need to write a program to look up references like this.
     
  6. Jan 8, 2016 #5
    lol, you lazy dog.
     
  7. Jan 8, 2016 #6
    The old UNIX command line interface is a lot more powerful than a point-and-click GUI like Windows. It's like having a toolbox instead of having to buy everything complete.

    One thing I did that I've never seen mentioned anywhere is to do automated editing on files.

    Another was to modify programs in such a way that if something went wrong it went grossly wrong. Gross errors are much easier to fix than subtle errors. Ideally you'd want a compile-time error. But I can't remember a specific example.
     
  8. Jan 8, 2016 #7

    jtbell

    User Avatar

    Staff: Mentor

    I take "laziness" here to mean things like avoiding copying and pasting a section of code multiple times (and changing variable names if necessary) by writing a function or module to accomplish the task. Or using a pre-written library or module instead of writing your own code, whenever possible.
     
  9. Jan 8, 2016 #8

    Borg

    User Avatar
    Science Advisor
    Gold Member

    For me, it currently means rewriting whole sections of an existing application to unscrew the complicated mess that a previous developer built. The two phrases that I hate to hear developers utter are "That will look good on my resume" and "Job security". Neither of them has the project's best interests at heart. I'm sure that Mr. Complexity loved both of those phrases. ?:)
     
  10. Jan 8, 2016 #9

    Svein

    User Avatar
    Science Advisor

    You mean, like awk?
     
  11. Jan 8, 2016 #10
    Probably Bill Gates: “I choose a lazy person to do a hard job. Because a lazy person will find an easy way to do it.”

    Jenkins. Jenkins makes my job so easy, especially automated testing.

    Get familiar with curl, most websites and services you will use as an engineer with have a REST interface.

    Get good at shell and bash and learn how to use aliases, that way you don't have to cd all over the place. pushd and popd are very useful.

    Learn to use virtual machines, it's so nice to be able to duplicate my setup, run something that might be destructive, and not have to rebuild my machine afterwards.


    We aren't lazy, we just get annoyed doing the same thing over and over again, and that's a lot of what engineering is. That's true with any job, we're just better at doing it because of experience.
     
  12. Jan 8, 2016 #11

    QuantumQuest

    User Avatar
    Gold Member

    This idea of laziness - although commonly exaggerated among not-programmers, still holds more or less but in a much more fine-grained way. With too many programmers/developers out there, so much code all over the web and so many libraries and modules built into and around every programming language - meaning compilers, debuggers, editors, libraries and all other stuff that every modern language/edition comes with, laziness and its art, is translated mainly into finding the best possible solution - which can too end up as a nightmare, but you're not beginning from scratch as it was the case, some years ago. Adding into account that almost all good programming secrets and habits have been published somewhere on the web and been demystified appropriately and that teamwork is nowadays how modern development is done, we conclude that laziness, impatience and hubris is not what used to be; they have a totally different form and are not anymore dependent so much on the art of good programming, but they have a rather procedural style. However I think that every well - educated and experienced programmer can always find the way to take advantage of the art to be a programmer.
     
  13. Jan 8, 2016 #12

    Mark44

    Staff: Mentor

  14. Jan 8, 2016 #13
    ex, the ancestor of vi, can run off of a script.
     
  15. Jan 8, 2016 #14
    I slowly realized that this was the true goal of much engineering. I'm sure it is true in other areas as well.
     
    Last edited: Jan 8, 2016
  16. Jan 8, 2016 #15

    FactChecker

    User Avatar
    Science Advisor
    Gold Member

    Awk and sed were some early tools. I often use Perl scripts to edit or auto-generate code. The 3 main techniques that I use often are:
    1) vi allows you to pipe lines to external programs (I use Perl scripts) that can be as complicated as you like and the printed results are inserted in place of the original lines.
    2) Read files of code in, manipulate / modify the code, and print out the results.
    3) make templates with place-holders where code should go. Perform the tasks to determine what code should go at each place-holder. Replace them and print the results.
     
  17. Jan 8, 2016 #16

    Svein

    User Avatar
    Science Advisor

    I have seen that in "general" C programs. Thousands of #define and #ifdef ...
     
  18. Jan 9, 2016 #17

    FactChecker

    User Avatar
    Science Advisor
    Gold Member

    That is better in most situations.
    I used templates a few times in the last couple of months. Once there were about 40 programs that I needed to pull parts out of and put those in a different context. There was a lot of modification that had to be done and could be automated. I was lucky that the original programs were done methodically enough to automatically find the required parts. It wasn't worth trying to automate a complete conversion, so there was still some work to do by hand.
    It may not have been the smartest way to do it, but it got the job done fairly quickly.
     
  19. Jan 9, 2016 #18
    Sublime Text is useful, especially the column selection / editing. I also try to keep my code so that things are aligned vertically. This way when I have a bunch of similar statements that differ only by arguments for example, I can write most of the text for them simultaneously. For example,
    Code (C):

      verts[ OFFSET     ] =                   Vec3( c, r, h1 );
      verts[ OFFSET + 1 ] = verts[ OFFSET ] + Vec3( 0, 1, h2 );
      verts[ OFFSET + 2 ] = verts[ OFFSET ] + Vec3( 1, 1, h3 );
      verts[ OFFSET + 3 ] = verts[ OFFSET ] + Vec3( 0, 0, h4 );
      verts[ OFFSET + 4 ] = verts[ OFFSET ] + Vec3( 1, 1, h5 );
      verts[ OFFSET + 5 ] = verts[ OFFSET ] + Vec3( 1, 0, h6 );
     
    Can be first made as this with the same effort as only typing one line. Of course I could just copy and paste, but I prefer to use the column selection tool more.
    Code (C):

      verts[ OFFSET  +   ] = verts[ OFFSET ] + Vec3(  ,  , h );
      verts[ OFFSET  +   ] = verts[ OFFSET ] + Vec3(  ,  , h );
      verts[ OFFSET  +   ] = verts[ OFFSET ] + Vec3(  ,  , h );
      verts[ OFFSET  +   ] = verts[ OFFSET ] + Vec3(  ,  , h );
      verts[ OFFSET  +   ] = verts[ OFFSET ] + Vec3(  ,  , h );
      verts[ OFFSET  +   ] = verts[ OFFSET ] + Vec3(  ,  , h );
     
    https://www.sublimetext.com/docs/2/column_selection.html

    Another thing that I try to do is make sure that my variable, function and class names are find and replaceable. This means that one variable name isn't a sub-string of any other string in the files. This also can help with searching through your files for certain things.

    Probably one of the most helpful things I do is try to write DRY and modular code. Which I don't always do, but when I don't it can often be a pain to manage the code, because if you change some logic in one place, but have that same logic repeated somewhere else, or something that depends on that logic somewhere else, you have to remember to keep these parts 'in synch' and it can lead to time consuming bug fixing or modification. What I would like is a tool that helps me find violations to the DRY principle and maybe make suggestions. For example, it would say that these specific three sections of code do basically the same thing, you replace them with function calls to this parametrized function. Apparently Visual Studio has something like this, but more primitive (basically just finds repeated text).
     
  20. Jan 9, 2016 #19

    Ibix

    User Avatar
    Science Advisor

    As much as possible, make sure that functions do one thing. It's far more common to want to do one thing again than to want to do some sequence of things.

    Take into account the programming skills of your colleagues. I'm easily in the top five or ten percent best programmers in my place of work. I find I have fewer support calls if the stuff I write is a bit less clever (it makes maintenance harder for me, but easier for everyone else).
     
  21. Jan 10, 2016 #20

    Mark44

    Staff: Mentor

    Excellent advice. For a given piece of software, the vast majority of the software development life cycle is in the maintenance phase, in which programmers who didn't write the code have to modify your code to fix bugs. If the code you (the original developer) wrote, is overly "clever," the chances that a maintenance programmer will be able to understand your cleverness are lower, thereby increasing the chances of introducing new bugs into the code in efforts to fix old bugs.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Share Your Tricks for Satisfying Laziness in Your Programming
  1. Crash your IE (Replies: 9)

Loading...