Share Your Tricks for Satisfying Laziness in Your Programming

  • Thread starter Jarvis323
  • Start date
  • Tags
    Programming
In summary, the conversation highlights the concept of "lazy" programmers, who are actually efficient and smart in their work habits. These programmers automate tasks, use tools wisely, and write reusable and easily modifiable code. Some tricks and tools mentioned include UNIX command line interface, automated editing on files, and using pre-written libraries and modules. The conversation also touches on the importance of being lazy in the programming world and how it has evolved with the abundance of resources available.
  • #1
Jarvis323
1,243
986
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.
 
Technology news on Phys.org
  • #2
Jarvis323 said:
People say the best programmers are 'lazy'.
Where did you get that?
 
  • #3
Borg said:
Where did you get that?
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:
  • #4
A link or reference always helps - Laziness, Impatience Hubris.
Laziness
The quality that makes you go to great effort to reduce overall energy expenditure. It makes you write labor-saving programs that other people will find useful, and document what you wrote so you don't have to answer so many questions about it. Hence, the first great virtue of a programmer. Also hence, this book. See also impatience and hubris. (p.609)
Impatience
The anger you feel when the computer is being lazy. This makes you write programs that don't just react to your needs, but actually anticipate them. Or at least pretend to. Hence, the second great virtue of a programmer. See also laziness and hubris. (p.608)
Hubris
Excessive pride, the sort of thing Zeus zaps you for. Also the quality that makes you write (and maintain) programs that other people won't want to say bad things about. Hence, the third great virtue of a programmer. See also laziness and impatience. (p.607)
That kind of 'laziness' makes more sense in the programming world. I really need to write a program to look up references like this.
 
  • Like
Likes mfb and nsaspook
  • #5
Borg said:
I really need to write a program to look up references like this.
lol, you lazy dog.
 
  • #6
Jarvis323 said:
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.

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.
 
  • Like
Likes FactChecker
  • #7
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.
 
  • Like
Likes gjonesy
  • #8
jtbell said:
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.
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. ?:)
 
  • #9
Hornbein said:
One thing I did that I've never seen mentioned anywhere is to do automated editing on files.
You mean, like awk?
 
  • #10
Borg said:
Where did you get that?
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.
 
  • #11
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.
 
  • #12
  • #13
Svein said:
You mean, like awk?

ex, the ancestor of vi, can run off of a script.
 
  • #14
Borg said:
"That will look good on my resume"

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:
  • #15
Svein said:
You mean, like awk?
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.
 
  • #16
FactChecker said:
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.
I have seen that in "general" C programs. Thousands of #define and #ifdef ...
 
  • #17
Svein said:
I have seen that in "general" C programs. Thousands of #define and #ifdef ...
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.
 
  • #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,
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.
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).
 
  • #19
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).
 
  • Like
Likes Borg, FactChecker and Jarvis323
  • #20
Ibix said:
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).
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.
 
  • Like
Likes FactChecker
  • #21
Mark44 said:
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.
Amen! One of the traps that so many fall into is that they are "so smart that they are stupid". Simpler is better.
 
  • #22
FactChecker said:
Amen! One of the traps that so many fall into is that they are "so smart that they are stupid". Simpler is better.
Not sure I completely agree there. There are times when a little complexity is worth it.

I had a task the other day that required me to do the same three things for about eighty variables. The least complex thing to do is write that out long-hand. But checking that it is all consistent is horrible (and assurance is a serious issue for us). However, the language I have the dubious pleasure of using (SAS) includes a "macro language" rather like the C pre-processor. I could define a macro variable containing the variable names and a macro to loop over the variables and auto-generate the same code for each one.

This macro language is a more complex programming technique than some of my colleagues would be comfortable with (particularly as it's a very ugly language). But in this case I think "tough". The advantage from the complexity vastly outweighs the complexity.

I added detailed comments.
 
  • Like
Likes FactChecker
  • #23
Template meta-programming comes to mind. It can help a lot with both performance and generality, but very few people can understand it. Still it's worth it for serious library code. The fact is that there are many projects that only a small percentage of people should be allowed to touch. For example the STL, Boost, Thrust, etc. Then again, I'm not a fan of some Boost libraries because I think some of them are too complex, not for performance reasons, but to make them extremely (unnecessarily) general. This is sort of how I feel about C++ 'Concepts' in some cases. But of course most of the people who have spent years focusing on studying these advanced features in depth would probably disagree.

Of course elegance, and simplicity are both good things, but often there are trade-offs you make when balancing things like performance, generality, security, accuracy, and complexity. Everything you do should be justified.
 
  • #24
Ibix said:
Not sure I completely agree there. There are times when a little complexity is worth it. ... I could define a macro variable containing the variable names and a macro to loop over the variables and auto-generate the same code for each one... The advantage from the complexity vastly outweighs the complexity. I added detailed comments.
I agree. I made a blanket statement that oversimplified. Using an advanced method for the right reason is fine. A judicious choice needs to be made. Avoid doing something advanced just for ego , to show off, or to try a new technique.
 
  • Like
Likes Ibix
  • #25
Modularize is the best thing to learn how to do. I've written dozens of projects that create SSH connections, I have one set of codes that do it. Any time I need more functionality, I add it to my custom module, that way if another project needs the same thing in the future, it's already there without any copy/paste. Any time you optimize your code, or fix a bug, having all code in one location allows you to upgrade all of your projects at the same time.

Something I've found extremely useful that I rarely see other programmers do is to take advantage of dynamically loaded libraries. Learn how to write them. This is really nice because you can not only port your code between projects, you can actually port it between LANGUAGES. That ssh code that I mentioned is written in C, but I use the same code when I use PHP too. I can only do that because I wrote it as a shared library.
 
  • #26
I guess the laziest possible thing to do is use a compiler or even a runtime interpreter like BASIC instead of writing everything in assembly language.
It is kinda handy though.
 
  • #27
rootone said:
I guess the laziest possible thing to do is use a compiler or even a runtime interpreter like BASIC instead of writing everything in assembly language.
It is kinda handy though.
If we want to go to that extreme, even lazier would be to write your code in assembly rather than by doing all of the calculations by hand (or worse, in your head).
 
  • Like
Likes QuantumQuest
  • #28
Mark44 said:
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.
The project that I am currently working on has this problem. The original architect of this mess used every trick that he could find in the Spring and Ext.js architectures. It is an obfuscated, over-architected, stove-piped mess. You have to stare at the code for hours just to figure out how variables are being set. Even then, we have to often just throw our hands in the air and take another path.

Yesterday, I was dealing with a restful call that can be called with different variables. Depending on the variable that you pass, you get different data. Unfortunately, you also get back different data formats for each of them. One came back as xml, another was json and the third came back as an html file. Of course none of the code is documented.

Problems like this are throughout the code. The various REST endpoints are using 7 versions of SearchRequest and SearchResponse objects in the code that are all completely different but pretty much do the same thing. Of course, there are translators all over the place that have been built to convert them. Most of this junk appears to have been written because everyone was so afraid of touching the original architecture for fear of breaking it. There is no rhyme or reason to the packaging of classes and NOTHING has been documented as to how it works. The database also doesn't follow standards that it should and needs an overhaul. Fortunately, we have a plan for fixing this mess and our manager is on board.
 

1. How can I be more efficient and productive while being lazy in my programming?

One trick for satisfying laziness in programming is to break down your tasks into smaller, manageable chunks. This will allow you to focus on one small task at a time and avoid feeling overwhelmed. Additionally, try to automate repetitive tasks using tools or scripts, and use keyboard shortcuts to save time and effort.

2. How can I avoid procrastination while still being lazy in my programming?

To avoid procrastination, create a schedule or set deadlines for yourself. This will help you stay on track and motivate you to complete tasks in a timely manner. Additionally, try to find ways to make programming enjoyable, such as incorporating fun challenges or working with a partner.

3. How can I maintain quality in my programming while being lazy?

One way to maintain quality in your programming is to write clean and efficient code from the beginning. This will save you time and effort in the long run, as you won't have to constantly go back and fix errors or refactor your code. Additionally, take breaks when needed to avoid burnout and maintain focus.

4. How can I balance my laziness with the need for continuous learning in programming?

Continuous learning is important in programming, but it doesn't have to be a time-consuming or tedious task. One way to balance laziness with learning is to incorporate learning into your daily routine, such as listening to podcasts or reading articles during breaks. You can also set aside specific times for learning, such as 30 minutes before or after your programming tasks.

5. How can I use my laziness to my advantage in programming?

Laziness can actually be a useful trait in programming. It can push you to find more efficient and effective ways of completing tasks. Embrace your laziness and use it to drive your problem-solving skills. Also, don't be afraid to ask for help or collaborate with others when needed.

Similar threads

  • Programming and Computer Science
2
Replies
65
Views
2K
  • Programming and Computer Science
Replies
4
Views
788
  • Programming and Computer Science
Replies
11
Views
4K
  • Programming and Computer Science
Replies
32
Views
2K
  • Sticky
  • Programming and Computer Science
Replies
13
Views
4K
  • Programming and Computer Science
Replies
10
Views
1K
  • Programming and Computer Science
Replies
15
Views
1K
  • Programming and Computer Science
Replies
13
Views
2K
  • Programming and Computer Science
Replies
29
Views
3K
Back
Top