There are best practices when writing code, but "habits" has always been a subjective term for me.  Everyone has their own ways of doing things. Here are some very basic fundamentals I try and follow

Master the Basics

Unlike Javascript, we, in the Ruby community, are lucky to have a limited choice of frameworks (sorry Sinatra fans). We are not constantly testing the new and shiny vitejs, or Vue.js or whatever flavor du jour is. We have more time to focus on one framework and master it. The same principles apply though: Master the basics of the Ruby language. This includes enumerables, classes, objects, closures and Proc objects. A good resource covering all Ruby, from Basic (meaning fundamental) to Advanced is Programming Ruby

Regular Expressions

Not only do regular expressions save you time, they also make the code more concise, elegant and easily convertible into other languages, should you decide to migrate your code in the future. There is obviously a Hockey stick learning curve, meaning basic  expressions are easy to write, but it can get - very - complex. A good resource is rubular.com. You can test your regular expressions online.

N.E.U.R.O.

You might not realize it but programming is a physical activity, not in the sense of a sports event but your overall health will impact your productivity, focus, and ultimately results. We, programmers, spend many hours hunched over our screens, not allowing our bodies to relax and our eyes to rest. We've all met senior programmers in very poor health. We must apply good habits to stay in shape and be productive in the long run. A good acronym to remember is NEURO, coined by Dr. Dean Sherzai, this summarizes the 5 pillars for a good health:

  • Nutrition
  • Exercise
  • Unwind (stress reduction)
  • Restore (sleep), and
  • Optimize (challenge your brain)
Nutrition: We tend to over-complicate nutrition, the best nutrition I ever read was from Michael Pollan in his book 'In Defense of Food'. Michael Pollan advises readers to "Eat food. Not too much. Mostly plants."

Exercise: A regular (daily), intense (not counting walking around the office), and not too long (25 to 30 minutes) routine is best to stay in shape. There are plenty of awesome workouts to choose from, I tend to favor burpees and running. Remember, sitting is the new cancer.

Unwind: And while mindfulness meditation isn’t a magic cure to bad stress, Dr. Dean Sherzai says it can help you to feel calmer and more focused, which ultimately supports brain health. Whether it’s yoga or breathing exercises, find time to practice mindfulness and de-stress every day.

Restore: "The best spa you can have is a planned sleep environment, with no noise or light"
Try to avoid eating for one-and-a-half to two hours before bedtime—especially high-energy sugary or fatty foods. Avoid your phone, TV, and computers for 30 minutes to one hour before bedtime if possible, since blue light turns on the circadian part of brain that wakes you up. And try this hack if you can’t fall or stay asleep: Write your worries on a sheet of paper by your bed as they come to you. “After a couple of months, your brain disassociates worry from sleep” says Dr. Dean Sherzai.

Optimize: Be social and challenge your brain

Learning is possibly the most important strategy to battle cognitive decline, but “when people retire, they’re less mentally active,” says Dr. Dean Sherzai. Try to keep your mind challenged at a high level—learn a new language, pick up a hobby like chess, or play a musical instrument. Set a specific, measurable, time-bound goals, like learning to learn to play “Hey Jude” on the guitar in the next month. Your brain will thank you for it.

Be Customer focused

We often forget that programs are made to solve real world problems, not find the most elegant solution to a theoretical question. We work for people who need our code to solve a specific problem. So instead of refactoring, optimizing and reviewing code, ship a A minimum viable product (MVP) version,  with just enough features to be usable by early customers who can then provide feedback for future enhancements.

Remember, you can always enhance a bad product, you cannot enhance a non existing product

Avoid hacks and workarounds

In the hurry to make code work, we sometimes rely on 'hacks' or 'workarounds'. While these can be short term solutions, they often stop to work after updating a gem, a library or the Ruby version. So as hard as this can be at the moment, use only 'clean code' practices, your future self will thank you.

Performance and Speed

DHH once said that "Performance is a feature". He is absolutely right: A fast loading page makes the app easier to debug, reload, reset and test for the developer. For the end user, a fast loading page (< 200ms) give a good user experience, makes it easier to undo actions and correct input errors. While it's easy to fall for the "early optimization" trap, a fast page is a must. No need to be fancy with the metrics here, keep all pages under a second of load page, write less code, limit the calls to the database and do as much processing on the browser as possible




Similar Stories


Enterprise

Automatic timesheets in Cosmolex

To sync phone records with Chrometa time entries, first export from T-Mobile, then import back into Chrometa. Read More

Enterprise

5 Resources to Boost Your Freelance Productivity

The modern freelancer has a lot of plates to spin on a daily basis in order to succeed – and there never seems to be enough hours in the day. Those that use their limited time most efficiently will blow past the competition and make an impact in their chosen market. . Read More

Enterprise

6 Tips to Maintain a Healthy Work-Life Balance during COVID

Confinement, lockdown, quarantine, shelter-in-place… .... Read More