Clean Code

Posted on Leave a comment

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);
    }
  }
);

Dev Blabber Ep 2: Microservices in Practice (with Ashwat)

Posted on Leave a comment

The Microservices architecture seems to be something that everyone is talking about but only few understand it well, let alone implement it and that too following all best practices. In this second episode, we are joined by a fellow DF member Ashwat to try and demystify the concept. Once we have the general definition out of the way, we’ll dissect a couple of real-world examples to see how the microservices architecture fits and solves their problems.

IRCTC, one of India’s most visited websites, is a great case in point. And so is Netflix, a company that sort of championed the use of this new architecture. We further discuss how the scaling cube works, and then take a look at decomposition, a key technique in deciding how to break a big application into micro services. Other topics discussed are bounded context, single responsibility principle (SRP), and common closure principle (CCP).

P.S. Apologies for the occasional background noise. Since this was a ‘live’ podcast, a few others from the DF community had joined to listen, learn, share and ask. I didn’t use the ‘mute by default’ setting because of which some mics made some noises. Will not happen from next time.

Dev Blabber Ep 1: Building an Open-Core Startup

Posted on Leave a comment

The first-ever episode of a brand new podcast series called Dev Blabber. It’s an initiative that I came up with as part of the awesome Digital Futurists community, where a bunch of geeks, entrepreneurs and seasoned executives discuss technology and software like crazy.

There was a discussion last week in the Coding channel—one of many channels within the DF community, and the one that I lead—regarding the topic of our next knowledge-sharing session. 4 topics were proposed, ranging from React performance optimization to cybersecurity. But this one, about building open-core startups, rose as the clear winner. While deliberating the format of this session, I thought of making it in the form of a podcast. The idea was instantly liked by most in my channel, and thus was born Dev Blabber.

I hope you enjoy this episode, which being the first one is very loosely structured and borderline chaotic. At least it’s true to its ‘blabber’ name.

P.S. More details about DF and how to join are coming soon. Watch out!

Whatever happened to…

Posted on 4 Comments

Software come and go. We like some, despise some and are neutral to others. Most of the good and useful software obtain a huge following and userbase, and usually survive for a very long time until either a better software appears or the technology changes. There also are software that are based on innovative ideas, but do not get sufficient attention, due to the lack of which they perish sooner than others.

And finally, there are software that initially create waves, catch all the attention due to the wonderful concepts they are based upon, attain significant fan following, and then… disappear! In this article, I am going to talk about just these kind of software, err, that were. These are such software that I would have hoped to see flourish till, at least, a couple more years. And yes, all these softwares were free.

Microsoft Reader

MS Reader was Microsoft’s noble attempt to change the way ebooks were read. Reader offered an actual book-like interface that was easy on eyes. It had two other advantages. First, the ebooks created in Reader format (.lit) were considerably smaller in size than an equivalent PDF. Second, it introduced text-to-speech in ebook reading (it would read the book word-by-word with adjustable voice speed).

In my opinion, MS Reader was a novell software. Many popular ebooks were published in “lit” format, but as time passed, such ebooks also disappeared. Today, the most ebooks we see are in PDF format.

Continue reading Whatever happened to…