Book Review — The Pragmatic Programmer

Posted on Leave a comment

Cross-posted from Goodreads

The Pragmatic Programmer is a structured collection of tips and practical advice for programmers looking to get better at their craft. In it, I found answers to many of my own doubts and dilemmas that I’ve experienced as a programmer for over a decade: questions of whether a particular approach or design is the right way, an overkill, or half-baked.

This one’s another seminal book on programming—like Clean Code—that I should’ve read years ago. Or maybe not: the first edition was written in 1999, where a lot of the technology and code samples discussed have become obsolete today. The second edition (2019) is a modern rewrite and what I picked up. While all code samples, as well as recommended languages, frameworks, libraries, and tools, have been revised the core concepts about being a ‘pragmatic’ programmer were true in 1999 and remain true 20 years later.

The gist of being a pragmatic programmer is that you deeply care about the quality of your software, write your code as a master craftsperson, and always keep your users at the forefront, but at the same time you also respect time commitments and know to stay away from the overengineering trap.

Although a lot of advice will feel ordinary to folks who’ve been programming for a few years, there are plenty of rock-solid gold nuggets of wisdom that will make reading the book worthwhile. Besides, the concepts that we know now and take for granted—like DRY and orthogonality—were literally born in this book (in 1999!).

Book Review — Clean Code: A Handbook of Agile Software Craftsmanship

Posted on Leave a comment

Cross-posted from Goodreads

If you are a software engineer and think, like so many others, that writing clean code is trivial and a skill that could be picked up anytime, this book will be a BIG eye-opener for you.

The book is written by a group of authors led by Robert C. Martin (aka Uncle Bob). As you will find out yourself, they are highly skilled professionals who are very serious about their craft and do not take code smells lightly. They follow the Boy Scouts Rule and go out of the way to ensure they leave code in a better state than they find it. These are the folks who have helped establish modern software engineering practices & patterns such as Agile and SOLID. The chapters where they rip apart popular and highly respectable open-source software (JUnit and Apache JCommons) are especially enjoyable as you get to see how good code could still be bettered.

Being a software engineer myself for a while now, I had a hundred questions regarding code quality and structure. I found all the answers here. Some were a confirmation of my beliefs, while others were new lessons to be learned.

I wholeheartedly believe in the book’s central tenet — writing clean code is an art, a sign of a software craftsman. Overall, it’s a great read and a time investment with a multi-fold ROI.

Clean Code

Posted on 3 Comments

There’s a bunch of technical books sitting in my Amazon wishlist for quite some time. Poor books! They could not end up in my shopping cart for a myriad of reasons, laziness to read being chief amongst them.

The importance of reading technical books simply cannot be overstated. Or reading articles, for that matter. Reading is what helps you to improve your craft, keeps you up to speed with the topics you care about, makes you a better version of yourself in your desired skill. Personally, I’ve found books to be more useful than online courses. I have nothing against online learning, I’m all for it. I have end-to-end finished a tonne of courses on Udemy, Pluralsight, Coursera, etc. The things that go for me with books are that I can take them anywhere (even where there’s no Internet), highlight important parts, scribble my own thoughts and most importantly learn without distractions. The thing about books being little portable time machines is true.

Recently when I was casually digging my Twitter timeline, I came across this book called “Clean Code”. Someone had written life-changing praises about it. Out of nowhere, I decided to order. Out I went to Amazon.in, found the book, read a few reviews, noticed that there was no discount, and hit the Buy Now button.

Clean Code is a book about software craftsmanship. It’s a must-read for anyone who cares about their craft.

I am a little more than halfway through the book, and boy, it is life-changing. It’s written in an authoritative tone by a bunch of regarded software engineers with decades of development experience. The experience clearly shows! Chief among the authors of the book is Robert C. Martin, who is one of the founders and foremost popularizers of SOLID principles and Agile methodology. I have thoroughly enjoyed the book so far, and am looking forward to finishing it. It’s safe to say that this book has reignited my craving for technical books. Next up I’ll probably pick up a Martin Fowler.

Using the learned clean code principles, I was able to transform this ugly chunk of code at work in a beautiful verse below it. The code is customization on top of Sitecore‘s JSS Node Proxy open source program.

Which code snippet is easier to read?

Object.keys(tenants).forEach((key) => {
  const tenantName = tenants[key];
  const proxyConfig = config.initConfig(tenantName);

  server.post(
    `/:lang((${routesLangs}))/${tenantName}:paymentRoute((${intermediatePaymentRoutes}))`,
    bodyParser.urlencoded(),
    (req, res) => {
      handlePaymentIntermediateRoute({
        paymentData: req.body,
        path: req.params.paymentRoute,
        lang: req.params.lang || DEFAULT_LANG,
      }).then((svcData) => {
        proxyConfig.serverBundle.renderView(
          (param, html) => {
            res.send(html.html);
          },
          req.path,
          svcData,
          { userAgent: req.headers['user-agent'] }
        );
      });
    }
  );

  server.use(
    `/:lang((${routesLangs}))/${tenantName}([/].*)?`, // eg. /((en|ar))/yasisland/wishlist
    (req, res, next) => {
      if (req.originalUrl.indexOf('/-/media') === -1) {
        let originalUrl = req.originalUrl.replace(tenantName, '');
        originalUrl = originalUrl.replace('//', '/');
        req.originalUrl = originalUrl;
      }
      next();
    },
    scProxy(
      proxyConfig.serverBundle.renderView,
      proxyConfig,
      proxyConfig.serverBundle.parseRouteUrl
    )
  );
});
server.use(
  '*',
  (req, res, next) => {
    setPaymentRoutePreReqs(req, res, next);
  },
  (req, res, next) => {
    const envType = getEnvironmentType(req);
    const tenantName = getTenantName(envType, req);

    const paymentRoute = req.paymentRoute;
    if (paymentRoute) {
      handlePaymentRoute(req, res, tenantName, paymentRoute);
    } else {
      handleApplicationRoute(req, res, next, envType, tenantName);
    }
  }
);