<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.3">Jekyll</generator><link href="https://twodee.me/feed.xml" rel="self" type="application/atom+xml" /><link href="https://twodee.me/" rel="alternate" type="text/html" /><updated>2023-06-23T15:34:51+00:00</updated><id>https://twodee.me/feed.xml</id><title type="html">Twodee’s kitchen</title><subtitle>A software development blog by Dedipyaman Das (@2DSharp) </subtitle><author><name>Dedipyaman Das</name></author><entry><title type="html">Contextual exceptions</title><link href="https://twodee.me/blog/2019/10/22/contextual-exceptions" rel="alternate" type="text/html" title="Contextual exceptions" /><published>2019-10-22T00:00:00+00:00</published><updated>2019-10-22T00:00:00+00:00</updated><id>https://twodee.me/blog/2019/10/22/contextual-exceptions</id><content type="html" xml:base="https://twodee.me/blog/2019/10/22/contextual-exceptions">&lt;p&gt;Exceptions are beautiful programming constructs that are often misunderstood. They can allow you to effectively deal with cases where your application may fail AND provide a way to recover from it. Although, many don’t seem to understand why and when to really use them.&lt;/p&gt;

&lt;p&gt;Some end up overusing them to an extent that it gets difficult to understand the intent of the program and some (under/ab)use them in all sorts of ways I can’t imagine.
&lt;!--more--&gt;&lt;/p&gt;

&lt;p&gt;One of the worst ways to deal with exceptions is to simply print the stack trace. Java provides you an easy way to do that with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;e.printStackTrace()&lt;/code&gt;. It’s great for debugging in development, but in production? A complete no-no. Unfortunately, I have seen enough code in my life to believe that people do have the habit of pushing that to production.&lt;/p&gt;

&lt;p&gt;Another school of thought is that exceptions are evil and people downright try to avoid them. Yes, they do provide another exit point for our application to use, but that’s only for &lt;em&gt;exceptional circumstances&lt;/em&gt;. That means, it’s going to be a rarity, and you should be able to gracefully recover from it without ruining the user experience.&lt;/p&gt;

&lt;p&gt;If your application runs into exceptions just as much as a valid flow, you’re not using exceptions correctly, but that discussion is for another day. I am not going to talk about whether exceptions are good or bad and how they are useful or not.&lt;/p&gt;

&lt;p&gt;What I really want to talk about is exceptions within contexts.&lt;/p&gt;

&lt;p&gt;A common way to handle exceptions is to just rethrow them till the final caller ends up handling it. So when registering a new user, your data mapper throws an exception on persistence:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-java&quot; data-lang=&quot;java&quot;&gt;&lt;span class=&quot;nc&quot;&gt;DataMapper&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;persist&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Object&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;object&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;PersistenceException&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;And how is it handled?&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-java&quot; data-lang=&quot;java&quot;&gt;&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;UserRepository&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;save&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;User&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;PersistenceException&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;dataMapper&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;persist&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Now when we go higher on the domain layer, we expose the same exception to the caller - the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AccountService&lt;/code&gt;.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-java&quot; data-lang=&quot;java&quot;&gt;&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;AccountService&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;registerNewUser&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;User&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;MetaData&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
			&lt;span class=&quot;n&quot;&gt;repository&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;save&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;catch&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;PersistenceException&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;c1&quot;&gt;// do something with the exception&lt;/span&gt;
		&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;So your service now has to handle the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PersistenceException&lt;/code&gt; thrown by the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DataMapper&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Wait, do you see what happened there? You just exposed your implementation details to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AccountService&lt;/code&gt; - which is two levels higher than the data mapper.&lt;/p&gt;

&lt;p&gt;The point of abstraction is completely missed at this point. While you were trying to abstract things away using a repository in your service layer which in turn talks to a data mapper, you leaked an implementation detail embedded in your method signature quite explictly.&lt;/p&gt;

&lt;p&gt;How should the service layer deal with a implementation specific exception? Fear not, we can do worse.&lt;/p&gt;

&lt;p&gt;We can rethrow that and go one layer higher - maybe in a Model-View-Controller design - the call to the Service Layer is made from the controller’s context, so now the controller now has to handle the exception.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Inversion of Control, right?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;At this point the controller has no idea why its being handed a persistence exception. If it’s still hard for you empathize with the controller, let the controller rethrow it! Now where does the exception end up? The top level caller - the end user.&lt;/p&gt;

&lt;p&gt;The end user now sees a massive stack-trace:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;javax.persistence.PersistenceException: Unable to build entity manager factory
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:81)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:54)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
at com.uzh.platform.api.util.AssignmentUtil.findAll(AssignmentUtil.java:20)
at com.uzh.platform.api.services.GetAssignments.getAssignments(GetAssignments.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:151)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:171)
...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Maybe you have been printing the stack trace all your life and aren’t intimidated by it when you see it. But think about it from your layman user’s perspective. Does it make any sense to the poor user at all?&lt;/p&gt;

&lt;p&gt;No. They would panic and call customer support immediately, and you know what they’d do? They would send you a picture of the stack trace clicked on their phones. Which at this point, is essentially &lt;em&gt;rethrowing&lt;/em&gt; the exception back to YOU. Only this time, your money is on the line.&lt;/p&gt;

&lt;p&gt;Now, it’s your turn to ask them what really happened and what they clicked and how this came about. You try to &lt;em&gt;understand the context&lt;/em&gt; and fix the issue.&lt;/p&gt;

&lt;p&gt;If you have been developing software for more than a year, you’ll know that when you go higher the abstraction level - the more vague the cause of the problem becomes. Most end users are not going to be of much help unless you have a lot of well paid and patient support representatives.&lt;/p&gt;

&lt;p&gt;It could have been avoided by simply saying something sensible like: “Something went wrong in our servers! We are fixing it ASAP.” to the user.&lt;/p&gt;

&lt;p&gt;This would make perfect sense to your customers, and in most cases they’d simply wait till it gets fixed. It’s understandable in their &lt;em&gt;context&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;I take this opportunity to coin the term &lt;strong&gt;“Contextual Exception”&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The idea is to wrap implementation specific exceptions thrown by low level parts of the code to domain specific exceptions that fits the context from which the method was called till the point that it stops being an exceptional case for the caller in the context.&lt;/p&gt;

&lt;p&gt;This can later be handled sensibly at a higher level of abstraction to deliver a useful feedback to the caller and continue.&lt;/p&gt;

&lt;p&gt;So the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PersistenceException&lt;/code&gt; thrown by the data mapper in our first example, can be handled by the UserRepository itself, which can then find the root cause of the exception and handle it appropriately. The UserRepository understands what could have happened in the data mapper layer and can deal with it.&lt;/p&gt;

&lt;p&gt;For example, in JPA, a foreign key constraint violation throws a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PersistenceException&lt;/code&gt; as well. You can catch that in your repository and wrap it in a (domain specific) &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserExists&lt;/code&gt; exception, which makes perfect sense to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AccountService&lt;/code&gt;. Now, when registering an account, a non-unique email address may be entered. This is expected by your controller.&lt;/p&gt;

&lt;p&gt;But even though you check for uniqueness before hand with a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;select&lt;/code&gt; query, there may be some race conditions when you may end up entering a value which becomes non-unique. Like two users simultaneously trying to register with the same email address. One of them will register first and your check at the beginning will fail.&lt;/p&gt;

&lt;p&gt;The only way for JPA to tell you that such an exception occurred is by throwing an exception at a low level. In such a case, your repository has to graciously recover from that and wrap it into something meaningful to the upper layer - that is the account service.&lt;/p&gt;

&lt;p&gt;Then what about the exception to be thrown to the controller? In most cases, you shouldn’t throw an exception back to the controller. You should handle it right there in the service layer and casually let the controller know that the email address has already been taken.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Why?&lt;/em&gt; Because this is not really an exceptional case for the controller. The controller expects users to enter non-unique email addresses and usernames. It has no idea about the persistence layer or any of the implementation details which may raise race conditions.&lt;/p&gt;

&lt;p&gt;The account service may use some sort of notification system to convey the message to the controller and the controller can turn it into a user friendly representation or just pass it to the view to do that. Now the account service can look like this:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-java&quot; data-lang=&quot;java&quot;&gt;&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;AccountService&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;registerNewUser&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;User&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;MetaData&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Notification&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;note&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
			&lt;span class=&quot;n&quot;&gt;repository&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;save&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;catch&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;UserExists&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
			&lt;span class=&quot;n&quot;&gt;note&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;email&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;The email has already been taken&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Controller&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;registration&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Request&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;accountService&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;registerNewUser&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;meta&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;note&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;note&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;isEmpty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;())&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;c1&quot;&gt;// do something useful&lt;/span&gt;
		&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;One thing to note is that exceptions can be costly, especially while catching and unwraping them. That’s one reason why people call them evil. But exceptions are there for a good reason - To deal with exceptional cases, and such cases shouldn’t happen in your normal flow of operations, at least in that context.&lt;/p&gt;

&lt;p&gt;A user entering non-unique email addresses is not exceptional to the controller, but a sudden connection loss with the account service on a network is very much an exceptional situation.&lt;/p&gt;

&lt;p&gt;In that context, the appropriate party should raise an exception and this should be handled by the controller in a graceful way while logging the cause for debugging.&lt;/p&gt;

&lt;p&gt;Yes, there are some cases where rethrowing the exceptions and letting them bubble up is the best option but that’s usually when that’s your &lt;em&gt;only&lt;/em&gt; option. Again, it largely depends on the context and how your system is built.&lt;/p&gt;

&lt;p&gt;If you are going to (re)throw exceptions, ask yourself this - does it make sense for the one receiving the exception? In most cases, your answer would be “no”.&lt;/p&gt;

&lt;p&gt;Handle exceptions with care.&lt;/p&gt;</content><author><name>Dedipyaman Das</name></author><category term="Programming" /><summary type="html">Exceptions are beautiful programming constructs that are often misunderstood. They can allow you to effectively deal with cases where your application may fail AND provide a way to recover from it. Although, many don’t seem to understand why and when to really use them. Some end up overusing them to an extent that it gets difficult to understand the intent of the program and some (under/ab)use them in all sorts of ways I can’t imagine.</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://twodee.me/assets/blog/exception.png" /><media:content medium="image" url="https://twodee.me/assets/blog/exception.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Design patterns - to do or not to?</title><link href="https://twodee.me/blog/2019/10/19/design-patterns" rel="alternate" type="text/html" title="Design patterns - to do or not to?" /><published>2019-10-19T00:00:00+00:00</published><updated>2019-10-19T00:00:00+00:00</updated><id>https://twodee.me/blog/2019/10/19/design-patterns</id><content type="html" xml:base="https://twodee.me/blog/2019/10/19/design-patterns">&lt;p&gt;When I came across design patterns a few years back, they seemed like a solution to everything. There wasn’t a problem that one of the design patterns couldn’t solve. It was almost analogous to mobile apps. &lt;em&gt;There’s an app for everything these days&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;For those who don’t know yet, design patterns are well defined patterns of reusable solutions that are followed to solve commonly recurring problems in the software engineering world.
&lt;!--more--&gt;&lt;/p&gt;

&lt;p&gt;The term &lt;em&gt;design patterns&lt;/em&gt; surfaced from the legendary book by the &lt;strong&gt;Gang of Four&lt;/strong&gt; (Erich Gamma, et al.) - &lt;a href=&quot;https://en.wikipedia.org/wiki/Design_Patterns&quot;&gt;&lt;strong&gt;Design Patterns&lt;/strong&gt;: Elements of Reusable Object-Oriented Software (1994)&lt;/a&gt;. More than 2 decades old, this book is still very much relevant in the fast-moving software industry.&lt;/p&gt;

&lt;p&gt;Software Engineering being a young profession, we are struggling to find standard ways to do things. While we are trying to build something big, we end up adding dirty fixes and hacky features. No two engineers are same, and to achieve a common ground organizations enforce conventions and patterns to adhere to while individuals contribute.&lt;/p&gt;

&lt;p&gt;My first encounter with design patterns was when I needed to establish a way to keep a particularly expensive database connection to just have a single instance to be accessed everywhere. That’s when I came across the &lt;em&gt;Singleton&lt;/em&gt; pattern.&lt;/p&gt;

&lt;p&gt;I looked around for implementations of the Singleton pattern, and most examples I came across had a structure similar to this:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-java&quot; data-lang=&quot;java&quot;&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;HeavyObject&lt;/span&gt; 
&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;HeavyObject&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;instance&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;HeavyObject&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{}&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;HeavyObject&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getInstance&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; 
    &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    	&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;instance&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    		&lt;span class=&quot;n&quot;&gt;instance&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;HeavyObject&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;instance&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;There are a few things to note here:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The constructor is private. So, if you tried to instantiate it by calling: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new HeavyObject()&lt;/code&gt; it wouldn’t work.&lt;/li&gt;
  &lt;li&gt;The HeavyObject instance is a static property. Which means &lt;strong&gt;global state&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;You can only access it by calling &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HeavyObject.getInstance()&lt;/code&gt;, and it will return the same instance everytime.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Perfect!&lt;/em&gt;, I thought, as I replaced my current database connection with this, plus I enjoyed the lazy initialization goodness. It worked great and served my purpose. At some point, I was inclined to using it for almost every problem that I came across, or at least think about using it.&lt;/p&gt;

&lt;p&gt;Turns out, global state isn’t a particularly great idea. Global variables can wreak havoc if not used judiciously, and you may have tightly coupled pieces spilled everywhere in your project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Enter &lt;em&gt;Dependency Injection&lt;/em&gt;&lt;/strong&gt;: Trying to find ways to get around the Singleton pattern without using static, I found Dependency Injection (and the concept of Inversion of Control). In simple terms, you don’t create the dependencies you need, you ask for it and someone hands it to you.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://twitter.com/ircmaxell&quot;&gt;Anthony Ferrara&lt;/a&gt;, in his video presentation about DI explains it with the analogy of a house building robot. Your house building robot is programmed to take blocks of lumber and fit them together to build the walls. When it needs to build a doorway it has two options - To create each door out of raw materials, or to take a ready-made door and just add it to the house.&lt;/p&gt;

&lt;p&gt;The door is a dependency for the robot to build the house. If it were to create a door everytime it had to add a doorway, and then in the future, you realized that you don’t like the doors that the robot built - you’ll have break that door, everywhere.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-java&quot; data-lang=&quot;java&quot;&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;HouseBuilder&lt;/span&gt; 
&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;HouseBuilder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    	&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;block&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Block&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
    	&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;door&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Door&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;buildHouse&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    	&lt;span class=&quot;n&quot;&gt;makeWalls&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;block&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    	&lt;span class=&quot;n&quot;&gt;makeDoorWay&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;door&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;This class knows too much about how doors and blocks are built. Don’t let your classes know too much.&lt;/p&gt;

&lt;p&gt;Dependency injection solves the problem by handing over a readymade door to the robot. Now if you’d like a different door, you simply swap the old door with a new door.&lt;/p&gt;

&lt;p&gt;This &lt;em&gt;decouples&lt;/em&gt; your wall from any specific implementation of the door. The robot just asks for a door that satisfies specific needs like the dimensions in the form of a &lt;em&gt;contract&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Using dependency injection helps reduce tight coupling of code and enables us to switch between implementations of interfaces. This is inversion of control. The caller feeds the dependencies to the callee, rather than the callee creating its own dependencies.&lt;/p&gt;

&lt;p&gt;So we can change it to something like this:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-java&quot; data-lang=&quot;java&quot;&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;interface&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Door&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;lock&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;HouseBuilder&lt;/span&gt; 
&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;HouseBuilder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;LumberBlock&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;block&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Door&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;door&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    	&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;block&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;block&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    	&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;door&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;door&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;buildHouse&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    	&lt;span class=&quot;n&quot;&gt;makeWalls&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;block&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    	&lt;span class=&quot;n&quot;&gt;makeDoorWay&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;door&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Now that the door is an interface, we can switch out implementations in anyway we like. We may want a glass door at a store front and a wooden door in a house, and we can do that by simply injecting a different implementation.&lt;/p&gt;

&lt;p&gt;Dependency Injection is often carried out by &lt;em&gt;Dependency Injection Contrainers (DIC)&lt;/em&gt; which create the dependency for you, usually utilizing &lt;em&gt;reflection&lt;/em&gt; to traverse multiple levels of dependencies. This is often useful for managing dependencies but not always necessary.&lt;/p&gt;

&lt;p&gt;DICs can easily help you replace the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;static&lt;/code&gt;-based implementation of Singleton by asking the DIC to supply the same instance of the dependency. This easily reduces tight complexity and the evilness of singletons and global state. So this is how I ended up solving my &lt;em&gt;Heavy object Singleton problem&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;So far, we have established the advantage of writing to interfaces than to concrete implementations, we can also take advantage of another pattern called &lt;em&gt;Factory&lt;/em&gt; pattern. Dependency construction isn’t always an one liner &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new LumberBlock()&lt;/code&gt;. Factories are methods that enable creation of dependencies with complex instantiation.&lt;/p&gt;

&lt;p&gt;This can be further extended by using the &lt;em&gt;Abstract Factory&lt;/em&gt; pattern that creates an object depending on the context.&lt;/p&gt;

&lt;p&gt;For example, if you’re making a store, you’d probably want to be supplied with glass doors. When you are creating a fort, you’d probably looking at strong iron gates. The abstract factory deduces that type of door to be supplied depending on the context.&lt;/p&gt;

&lt;p&gt;As it is evident from the discussion above, it’s very easy to get lost in patterns while talking about them. You start off with some pattern and end up talking about something else.&lt;/p&gt;

&lt;p&gt;Usage of design patterns has been growing gradually, and with that comes individuals abusing them to an extent that it exponentially deviates from the original intent. I’ve come across a lot of codebases that agressively use patterns and even anti-patterns like Singleton.&lt;/p&gt;

&lt;p&gt;The concept is tempting and as a consequence codebases turn into a huge mess of design patterns on every page. I am guilty of committing this mistake.&lt;/p&gt;

&lt;p&gt;What I have learned from experience is to let design patterns surface based on a &lt;em&gt;need rather than a want&lt;/em&gt;. Like on my first introduction to Singleton, I &lt;em&gt;needed&lt;/em&gt; a way to access just one instance of a database connection.&lt;/p&gt;

&lt;p&gt;When you start &lt;em&gt;wanting&lt;/em&gt; to use patterns for the sake of using patterns, that’s when your codebase starts smelling and it ends up looking like:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-java&quot; data-lang=&quot;java&quot;&gt;&lt;span class=&quot;nc&quot;&gt;JSONDataStorageStrategy&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;datastore&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;AbstractDependencyBuilderFactory&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;createSingleInstance&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;jsonDataStorage&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;It doesn’t make any sense (not at least to me), and soon gets hard to decipher over time (I guess that’s where Java gets its bad rap from).&lt;/p&gt;

&lt;p&gt;Design Patterns isn’t a silver bullet - they have their usecases, pros and pitfalls. They come with their own gotchas and they fit in some cases better than others. Just because your colleague used a facade over the data mapper doesn’t mean that you’ll have to. Many libraries actively incorporate some bad design techniques this way.&lt;/p&gt;

&lt;p&gt;For example, &lt;em&gt;Active Record&lt;/em&gt; is often considered an anti-pattern is being used at many popular ORM-libraries with big corporations backing them.&lt;/p&gt;

&lt;p&gt;Anyhow, design patterns can be a great thing if used judiciously. Deciding on a use-case and trying out a simpler solution first should be done before jumping onto the GoF book. This can yield great results and improve the codebase signficantly.&lt;/p&gt;

&lt;p&gt;Recently, I came across the &lt;em&gt;Notification Pattern&lt;/em&gt; from &lt;a href=&quot;https://martinfowler.com&quot;&gt;Martin Fowler&lt;/a&gt;’s &lt;em&gt;Further Enterprise Application Architecture development&lt;/em&gt;. This turned out to be a great alternative to my previous exception-based validation approach by saving me some computational cost and allowing me to aggregate all the errors at once.&lt;/p&gt;

&lt;p&gt;With that said, we invent new patterns everyday and sometimes they add additional complexity to our codebase. One good rule of thumb while writing code is to make them reusable and do just one thing.&lt;/p&gt;

&lt;p&gt;One of the best strategies I have devised is to make a very local solution to a local problem first, and then generify it along the way.&lt;/p&gt;

&lt;p&gt;The entire goal of design patterns is reusability, and they may have consequences and tradeoffs that come along with them which we have to deal with.&lt;/p&gt;

&lt;p&gt;Questioning whether it’s really worth the additional complexity and designing a mitigation strategy for dealing with the tradeoffs beforehand will take you a long way than simply using a pattern just because someone else is.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;You ain’t gonna need it.&lt;/em&gt;&lt;/p&gt;</content><author><name>Dedipyaman Das</name></author><category term="Design-Patterns" /><category term="Programming" /><summary type="html">When I came across design patterns a few years back, they seemed like a solution to everything. There wasn’t a problem that one of the design patterns couldn’t solve. It was almost analogous to mobile apps. There’s an app for everything these days. For those who don’t know yet, design patterns are well defined patterns of reusable solutions that are followed to solve commonly recurring problems in the software engineering world.</summary></entry><entry><title type="html">Another Pycon, more community</title><link href="https://twodee.me/blog/2019/10/14/pycon2019" rel="alternate" type="text/html" title="Another Pycon, more community" /><published>2019-10-14T00:00:00+00:00</published><updated>2019-10-14T00:00:00+00:00</updated><id>https://twodee.me/blog/2019/10/14/pycon2019</id><content type="html" xml:base="https://twodee.me/blog/2019/10/14/pycon2019">&lt;p&gt;As I fly back to my university from Chennai after Pycon, I cannot stop recalling everything that has happened to me for the last 3 days. Leaving the Airbnb and going towards the airport wasn’t an easy thing for the mind. I had to pen down what’s been going on in my head for a release. 
&lt;!--more--&gt;&lt;/p&gt;

&lt;p&gt;After finishing my exams midst Durga Puja (which I was really looking forward to), I spent a few gloomy days in the hostel because I couldn’t go back home. Desperately needing a break, I was counting my days till Pycon.&lt;/p&gt;

&lt;p&gt;To be honest, I wasn’t as excited I was last year to go to Pycon - partly because I just had my exams done, and I couldn’t enjoy the 3-day holidays I got after that.&lt;/p&gt;

&lt;p&gt;I packed all my essentials on my backpack and ran towards the airport thinking that this will suffice. Boy, was I wrong. Upon reaching Chennai, I met up with Kuntal (&lt;strong&gt;@hellozee&lt;/strong&gt;) and a two more &lt;strong&gt;#dgplug&lt;/strong&gt; members with whom I will have been staying for the next few days.&lt;/p&gt;

&lt;p&gt;We got into the Airbnb, me being socially awkward, stayed silent for a while. The rest of the &lt;strong&gt;#dgplug&lt;/strong&gt; gang joined in with Pizzas and Pepsis. I got my mental cooldown over a game of Uno and having pizza for the first time after Fall, 2017.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;“Dedipyaman”&lt;/em&gt; is not an easy name to pronounce. We had a good laugh over people trying to pronounce my name. Even the Bengalis in the group were struggling. Now you know why this blog is called &lt;em&gt;“Twodee’s kitchen”&lt;/em&gt; and not &lt;em&gt;“Dedipyaman’s”&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Well, I was living with developers from different parts of the country. We had met for the first time, this did feel like home.&lt;/p&gt;

&lt;p&gt;At the Chennai Trade Centre, I made sure I collected my stickers first. I participated in my first challenge at the Jetbrains booth to bring home some goodies. I didn’t want to miss out on a T-shirt featuring my favorite set of IDEs in the world.&lt;/p&gt;

&lt;p&gt;Thoughtworks (I know it as the company Martin Fowler works at) gave me a nice Wireless Charger for a simple Binary Search snippet re-arrangement. I don’t have a phone that supports wireless charging. If the generous reader would like to gift this poor soul with a phone that supports Wireless charging, they can have a virtual hug from me.&lt;/p&gt;

&lt;p&gt;AQR presented me with a T-shirt, a cool coaster and a mousepad with USB slots. I am yet to figure out how that works, but as the first person who solved your Pycon challenge - I thank you for the goodies.&lt;/p&gt;

&lt;p&gt;As for the talks, I wasn’t sure how the silent conferences would turn out to be - but for a change, it worked out pretty well!&lt;/p&gt;

&lt;p&gt;I really loved David Beazely’s (&lt;strong&gt;@dabeaz&lt;/strong&gt;) concluding Keynote (although I’m not sure what his original intended topic was). He wrote a stack machine in front of a live audience, and then went on to do WASM with Python while making mistakes - like a normal human would. It was really fun to listen to his insights, and he deserved the whole standing ovation at the end. Python’s (or any language for that matter) future is what we make it.&lt;/p&gt;

&lt;p&gt;Pycon is not Pycon unless you walk till you tire your legs out. I went to random people, said hi, talked about our experiences. Met a couple of old faces too. Interestingly, a significant portion of Pycon attendees don’t write Python. Well, good to know that I am not the absolute minority.&lt;/p&gt;

&lt;p&gt;It was all cool and fun. At some point the goodies got heavy and it was a challenge for me to carry my backpack. Two days back, I had squatted and deadlifted after a long three week break. The DOMS (Delayed Onset Muscle Soreness) didn’t fade away, and the backpack somehow equalized the pain by hurting my upper back while the DOMS killed my lower back.&lt;/p&gt;

&lt;p&gt;I had a backpack situation that the genius of &lt;strong&gt;@hellozee&lt;/strong&gt; helped me solve. Lesson learned: &lt;em&gt;Carry another bag next time&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;But this time, Pycon for me was not really about the conference - it was about the people. I realized, you don’t really feel the impact of Open Source at a personal level, unless you spend time with the community in real life. Yeah, Open source is changing the world - but how its bonding people from all groups, ages, sexes, races - can only be felt when you play a game of cards or have dinner together.&lt;/p&gt;

&lt;p&gt;Or when you have the tech-stack wars: &lt;em&gt;No one writes JS willingly&lt;/em&gt;, &lt;em&gt;Java yields loooong lines…&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Unfortunately, I live in a tightly packed bubble with almost no exposure to the outside world. The only communication I do get with like minded people is through online channels. I didn’t know about &lt;strong&gt;#dgplug&lt;/strong&gt; being this online IRC-based thing and meeting at least once a year at Pycon.&lt;/p&gt;

&lt;p&gt;The way they came together as a family, laughing at each others jokes and enjoying the moment - it was something special. I have had the chance to meet and talk to them about what they do, what tools they use on a daily basis, their adventures in life. A real life human-to-human experience sharing.&lt;/p&gt;

&lt;p&gt;So, here’s my take on my experience in this year’s Pycon:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Coding solo is great, you can write code all the day alone and get things done. The community is greater, you can empathize, share, and grow together.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I would like to thank all of the &lt;strong&gt;#dgplug&lt;/strong&gt; folks to make me feel welcome and a part of the group. It was something I really needed, but didn’t know that I did.&lt;/p&gt;

&lt;p&gt;As I arrived at my dorm room, I conclude this with a heavy heart. I look forward to the next conference and hopefully will be a more social person.&lt;/p&gt;

&lt;p&gt;Pycon was all worth it.&lt;/p&gt;

&lt;p&gt;If you haven’t read it yet, check out this post about my first time Pycon experience: &lt;a href=&quot;https://www.twodee.me/blog/2018/10/29/pycon&quot;&gt;How Pycon India 2018 changed the way I see things&lt;/a&gt;. To sum up, I can reuse what I said on my last Pycon post:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;It was never just about Python. It has always been about the &lt;strong&gt;community&lt;/strong&gt;.&lt;/em&gt;&lt;/p&gt;</content><author><name>Dedipyaman Das</name></author><category term="Experiences" /><summary type="html">As I fly back to my university from Chennai after Pycon, I cannot stop recalling everything that has happened to me for the last 3 days. Leaving the Airbnb and going towards the airport wasn’t an easy thing for the mind. I had to pen down what’s been going on in my head for a release.</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://twodee.me/assets/blog/pycon2019.png" /><media:content medium="image" url="https://twodee.me/assets/blog/pycon2019.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">PHP sucks, can it suck less?</title><link href="https://twodee.me/blog/2019/09/26/php" rel="alternate" type="text/html" title="PHP sucks, can it suck less?" /><published>2019-09-26T00:00:00+00:00</published><updated>2019-09-26T00:00:00+00:00</updated><id>https://twodee.me/blog/2019/09/26/php</id><content type="html" xml:base="https://twodee.me/blog/2019/09/26/php">&lt;p&gt;PHP has garnered a bad reputation in the software market. Many developers hold strong opinions against the language and to some extent, that’s correct. Over the last few years, although PHP has gone through an evolution and is it the same &lt;em&gt;“Fractal of Bad Design”&lt;/em&gt;?
&lt;!--more--&gt;&lt;/p&gt;

&lt;p&gt;Yes, I admit it. &lt;em&gt;PHP sucks.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;And I shamelessly write PHP code, so I must suck too, right?&lt;/p&gt;

&lt;p&gt;As popularly stated in the famous article &lt;a href=&quot;https://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/&quot;&gt;PHP: a fractal of bad design&lt;/a&gt; :&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;PHP is an embarrassment, a blight upon my craft. It’s so broken, but so lauded by every empowered amateur who’s yet to learn anything else, as to be maddening. It has paltry few redeeming qualities and I would prefer to forget it exists at all.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The article has only gotten popular over the years, and it’s still being circulated over Quora (One of them being the founder himself, Adam D’Angelo).&lt;/p&gt;

&lt;p&gt;And while the article came out, yes, it was right. It was badly designed and badly implemented. The users made it worse. While PHP came along, it didn’t originally plan to be as massively used as it is today. Since it was so easy to adapt to, people started using it everywhere. It worked to some extent.&lt;/p&gt;

&lt;p&gt;As soon as the web got more popular, we changed, our needs changed. PHP didn’t. It was still stuck behind, probably due to the community? It was inconsistent with its naming, it had the insecure &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mysql_*&lt;/code&gt; functions built into its design. There were a lot of gotchas in the language, and having used PHP for a long time, I know that it is a pain.&lt;/p&gt;

&lt;p&gt;But this is 2019. The article was written in 2012. I am surprised people still keep quoting that article &lt;em&gt;everywhere!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;C’mon people, PHP has changed (evolved) a lot, don’t tell me the public eye is too blind to see it.&lt;/p&gt;

&lt;p&gt;PHP has had some major pushes like the HipHop to HHVM movement from Facebook and PHP 7. Developers have recognized the issues that came along with it, and they have been addressing it so far. If you are living in 2019 and still writing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mysql_*&lt;/code&gt; functions (or blaming PHP for having that), you seriously need to learn to &lt;a href=&quot;https://en.wikipedia.org/wiki/RTFM&quot;&gt;RTFM&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So why this hatred still?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Well, as long as something’s popular - people will hate it. People hate Java, people hate C++. When millions use your product, you cannot expect everyone to be happy customers with every design decisions that you make. There will be people who don’t like your approach and that’s true for any remotely popular language.&lt;/p&gt;

&lt;p&gt;People often compare Python to PHP in the web context. I have nothing against Python, I think it’s a great language that fits the purposes it was intended for (scripting?) and purposes it was adapted popularly for (AI/ML/Data Science?).&lt;/p&gt;

&lt;p&gt;But here’s where Python fails to impress me against PHP:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;It’s slow. Not a deal-breaker (especially on the web), but I am making arguments for the sake of making arguments. If you still complain about PHP being ugly, I can complain it about being slow.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;It needs a framework for anything web. Initially, when I just wanted to get a Python application up and running for the web, I had the community continuously push me over to use Django or Flask. I hate being coupled to a framework, as many others would (and should) be too.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Whitespacing? Not a fan. Again, it’s not a deal-breaker, but having whitespace &lt;em&gt;mean&lt;/em&gt; something doesn’t make sense to me. I understand that it was a design decision to keep the lines cleaner, but when things break because I missed an invisible whitespace - it hurts my feelings.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Its Object-oriented model is alien to me. Access specifiers are done by enforcing conventions with underscores? Okay. No. Maybe it works for some folks, but I like things being implied explicitly rather than implicitly.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But okay, Python is a great language. It works great, it’s got a great community and yet - there are people who hate it. And that’s okay if you are remotely popular anywhere - you will have people not liking you.&lt;/p&gt;

&lt;p&gt;Javascript on the other hand - It’s something I really don’t like. It’s a matter of personal opinion. Especially after the fact that some Javascript dudes who are a few years older than me were trying to shove Node.js down my throat and bashing PHP for the time I was in front of them. Asserting that Node is far superior, safe and faster than PHP (and anything else for the web) and I should learn Node right away.&lt;/p&gt;

&lt;p&gt;They went as far as saying that PHP invented SQL injection. I stopped trying to speak at that point.&lt;/p&gt;

&lt;p&gt;Coming back to PHP:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do you still have/write legacy PHP code that follows the arcane PHP 5 approach?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I have a list for you:&lt;/p&gt;

&lt;h1 id=&quot;start-writing-oop&quot;&gt;Start writing OOP&lt;/h1&gt;

&lt;p&gt;While you can still write procedural PHP, the community has moved towards an object-oriented approach. It simply fits the new model and works great to have you structure the code well. With object-oriented, several clean coding practices like SOLID and DRY are automatically implied.&lt;/p&gt;

&lt;p&gt;OOP silently enforces clean structuring of your codebase and keep things separated better. Of course, it’s optional, if you like writing spaghetti code, no one’s stopping you. You can make the worst out of PHP and give yourself a bad name. But that’s entirely up to you, any language will allow you to do that. Not just PHP.&lt;/p&gt;

&lt;h1 id=&quot;strict-type-as-much-as-you-can&quot;&gt;Strict type as much as you can&lt;/h1&gt;

&lt;p&gt;While we are at the subject, also use Strict Types. It’s as simple as: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;?php declare(strict_types=1)&lt;/code&gt; at the beginning. Static typing surely helps you keep things consistent and safe. Yes, PHP is a dynamically typed language, and we need to squeeze that feature out of PHP sometimes. But in most cases, going by the safer path with strict types can save you from a lot of weirdness and unpredictability at runtime.&lt;/p&gt;

&lt;h1 id=&quot;namespaces-please&quot;&gt;Namespaces, please&lt;/h1&gt;

&lt;p&gt;The include statements on top of the page are no more common and the community recommends that you use namespaces to &lt;em&gt;“import”&lt;/em&gt; modules you need to &lt;em&gt;“use”&lt;/em&gt;. Its a means of abstraction over your raw PHP files that allows you to encapsulate the include logic.&lt;/p&gt;

&lt;p&gt;Yes, it could be weird to use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\&lt;/code&gt; as the namespace separator at first, but you’ll get used to it. Get rid of those includes and start using namespaces to put things into their correct places. Which brings me to my next point:&lt;/p&gt;

&lt;h1 id=&quot;composer&quot;&gt;Composer&lt;/h1&gt;

&lt;p&gt;If you are planning to start a PHP project, get &lt;a href=&quot;https://getcomposer.org/&quot;&gt;composer&lt;/a&gt; immediately. It’s a dependency management tool which allows you to define your dependencies, your application and test entry points and load dependencies from the central Packagist repository as you need them. It generates an autoloader for you, and that’s the only thing you should &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;include&lt;/code&gt; in your entire project.&lt;/p&gt;

&lt;h1 id=&quot;throw-away-mysql_&quot;&gt;Throw away &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mysql_*&lt;/code&gt;&lt;/h1&gt;

&lt;p&gt;All the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mysql_*&lt;/code&gt; functions have been deprecated for a long, long time and it has been removed in PHP 7 for good. So if you are still complaining about &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mysql_*&lt;/code&gt; functions being bad, please upgrade your PHP version. The best way to deal with a database as of now is to use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PDO&lt;/code&gt; with prepared statements. It’s a generic API that works quite well with a vast array of databases.&lt;/p&gt;

&lt;p&gt;The things that I like about PDO are: it’s clean, relatively modern design, object-oriented and consistent. You will move to exclusively use PDO in no time once you start a project with PDO.&lt;/p&gt;

&lt;p&gt;Again, don’t create DB wrappers like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DBConnection extends PDO&lt;/code&gt;. Just don’t. If you need some sort of abstraction over PDO, check out the Data Mapper pattern and some ORM like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Doctrine&lt;/code&gt; (and not some evil Active Record variant).&lt;/p&gt;

&lt;h1 id=&quot;separate-your-concerns&quot;&gt;Separate your concerns&lt;/h1&gt;

&lt;p&gt;Most of the bashing PHP gets today is because new developers mess it up so bad, that it smells worse than Javascript (I am opinionated, sorry). Because its easy to learn and get started with, newbies just can’t resist themselves from writing hacky code and deploying it to production.&lt;/p&gt;

&lt;p&gt;Other languages don’t get this because&lt;/p&gt;

&lt;p&gt;a) they have a steeper learning curve&lt;/p&gt;

&lt;p&gt;b) they give out a strict design strategy beforehand.&lt;/p&gt;

&lt;p&gt;Fix this by separating your concerns. I remember once I used to copy-paste portions of long functions to other files to do the same thing, but slightly differently. I understand why beginners do that.&lt;/p&gt;

&lt;p&gt;Start off by making your functions smaller.&lt;/p&gt;

&lt;p&gt;Break your codebase down to small pieces acting independently doing exactly one thing. Read more on SOLID and DRY principles.&lt;/p&gt;

&lt;p&gt;If you have a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;User&lt;/code&gt; class, don’t allow it to be able to create a message, encrypt the message and also send the message to another user.&lt;/p&gt;

&lt;p&gt;Incorporate libraries from the internet, people solved your problems with better testing well before you did. And they did it better. Whilst we may be tempted to have everything custom made, we tend to deviate from the actual business needs. Focus on your business logic, use what’s already available.&lt;/p&gt;

&lt;p&gt;But no tight coupling.&lt;/p&gt;

&lt;h1 id=&quot;psrs-to-the-rescue&quot;&gt;PSRs to the rescue&lt;/h1&gt;

&lt;p&gt;And finally, follow coding conventions and read on PHP-FIG. The PHP Standards Recommendations (PSRs) will allow you to have a consistent codebase that others can easily understand and extend. The standards will help you to write code that can be compatible with other code written by others, and that will save you from cursing yourself 3 months after you write some bad PHP code.&lt;/p&gt;

&lt;p&gt;This recommendation applies to every language in general. Follow coding conventions and strive to write better code. Of course, no one can stop you from being a “code-rebel”. We don’t have the technology to stop you from that yet.&lt;/p&gt;

&lt;p&gt;(Yes we do, coding standards checks during integrations can keep idiots at bay)&lt;/p&gt;

&lt;h3 id=&quot;a-few-concluding-words&quot;&gt;A few concluding words&lt;/h3&gt;

&lt;p&gt;Yes, PHP sucks. So does every other language. You just gotta deal with it.&lt;/p&gt;

&lt;p&gt;It’s up to you and your team to write code that looks like poetry rather than an ugly war cry. You can write severely bad Java code even with its verbosity and static typing.&lt;/p&gt;

&lt;p&gt;You were scared about starting your next project with PHP because your coworkers will judge? Go right ahead and do that. It’s your job and it’s your tool.&lt;/p&gt;

&lt;p&gt;Your coworkers are probably too free, maybe their code is still compiling.&lt;/p&gt;</content><author><name>Dedipyaman Das</name></author><category term="Clean-Code" /><category term="Opinions" /><summary type="html">PHP has garnered a bad reputation in the software market. Many developers hold strong opinions against the language and to some extent, that’s correct. Over the last few years, although PHP has gone through an evolution and is it the same “Fractal of Bad Design”?</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://twodee.me/assets/blog/phpsucks.png" /><media:content medium="image" url="https://twodee.me/assets/blog/phpsucks.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Technical debt</title><link href="https://twodee.me/blog/2019/09/23/technical-debt" rel="alternate" type="text/html" title="Technical debt" /><published>2019-09-23T00:00:00+00:00</published><updated>2019-09-23T00:00:00+00:00</updated><id>https://twodee.me/blog/2019/09/23/technical-debt</id><content type="html" xml:base="https://twodee.me/blog/2019/09/23/technical-debt">&lt;p&gt;Software development is cursed with an implied cost at any stage, no matter how elegant your solution looks at any point of time. The cost of fixing what you messed up. Humans write code, and code is prone to ugliness. This piles up over time and dealing with it is a challenge every team faces many times in their lifetime.
&lt;!--more--&gt;&lt;/p&gt;

&lt;p&gt;While building any sensible system with code filling more than a page you start breaking things down to pieces, if you aren’t you should. When you start abstracting things away into separate smaller modules, you start thinking about how to put them together. Oftentimes, you need to add one tiny feature and then one more, while trying to keep the initial structure you had in mind intact.&lt;/p&gt;

&lt;p&gt;Although the idea was clear at the beginning, the pieces don’t simply fit together as easily as you’d want them to be. So, you mess around the structure of the codebase a bit, just fine little harmless tweaks. As features accumulate, you start to see a big change that module’s structure.&lt;/p&gt;

&lt;p&gt;What starts off as a clean, well-structured module now became this horrible mess of hacky additions of features. At some point, you stop understanding what it was supposed to do, because it’s doing too many things.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;But it works.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;So you leave it behind, put a checkbox in your TO-DO list and move on with the next module. Then days after, your requirements change and you need to modify that module once again. Or maybe you’d like to integrate it with some other module. The confusing module is now hard to read, understand and extend. Moving any further would be an impossible task with it.&lt;/p&gt;

&lt;p&gt;You’ve two choices at this point-&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Discard it entirely and start fresh&lt;/li&gt;
  &lt;li&gt;Fix it&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Unless you’re building your first application which doesn’t do much, the first is usually not the best option. Especially in a project where you put significant amount of time thinking about and developing that module. It works, and it has some clever crafted code inside it, it’s just turned messy.&lt;/p&gt;

&lt;p&gt;Now you have to take a step and fix it.&lt;/p&gt;

&lt;p&gt;This is &lt;strong&gt;Technical Debt&lt;/strong&gt;. As in monetary debt, if you don’t repay your dues early on, the interests will accumulate and push you into a hard-to-return-from point.&lt;/p&gt;

&lt;p&gt;When you thought, &lt;em&gt;“hey, this works for now, we can fix that later”&lt;/em&gt; you fell a little deeper into the debt trap. Technical debt is the additional cost you implicitly added to your project by choosing an easier path that you will have to pay for in the future.&lt;/p&gt;

&lt;p&gt;Now what would have taken you 3 days of work, will take you about a week. It’s the cost of fixing the code (paying off the debt) + the cost of implementing the new feature.&lt;/p&gt;

&lt;h3 id=&quot;how-do-i-prevent-technical-debt&quot;&gt;How do I prevent technical debt?&lt;/h3&gt;

&lt;p&gt;You don’t. You can only minimize it. Think of it as a financial system, and do exactly what you’d do when you loan money off your bank. You pay the dues gradually. Once you are done implementing the first feature in your module, you take some extra time to remove that mess and make it saner.&lt;/p&gt;

&lt;p&gt;Yes, you did put extra time into it, but it lessened the burden for the next feature and decreased the overall cost. This gradual removal of mess enables you to fix the parts of your code that needs the most modifications over time, and hence needs to be the cleanest.&lt;/p&gt;

&lt;p&gt;Cleaning it off gradually over time will make sure the debt doesn’t accumulate to the point of no return over time. And it helps you keep the internal code quality fresh at the points where you need it the most.&lt;/p&gt;

&lt;p&gt;Recently, in a system I had used a factory to convert transfer objects to domain entities. It was initially meant to do just that, but I ended up validating the data and checking for redundancy from the persistence layer inside it. All within a factory. It was too smart at that point.&lt;/p&gt;

&lt;p&gt;Eventually I kept using this factory in too many pieces, and adding more logic to make it smarter. I started having a hard time connecting the pieces together and that was a clear violation of &lt;strong&gt;SRP&lt;/strong&gt;. I had to take a day off just to dumb the factory down to just be limited to creating the objects and not do too much.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tight coupling&lt;/strong&gt; is a major evil in a modular system and can often lead to code smell even in the most initially well thought out business logic. Coupling can end up contributing to the technical debt you accumulate over time, and you simply would be confused when something stops working in the cleaning up process.&lt;/p&gt;

&lt;p&gt;When you start paying off the dues at a much later stage in a tightly coupled system, you find yourself breaking things even more than you’d do normally. At that point the paying off process becomes a nightmare and takes huge effort to fix.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Unpopular opinion:&lt;/strong&gt; Don’t fix something that works and you seldom change.&lt;/p&gt;

&lt;p&gt;If your co-worker built a module that works perfectly fine and integrates just well enough for you to go on with - don’t bother about fixing it if you don’t modify it frequently enough. There’s little reason to fix something that confusing and doesn’t need fiddling with. If it meets your business requirements, leave it alone.&lt;/p&gt;

&lt;p&gt;Finally, &lt;strong&gt;write more tests&lt;/strong&gt;. Sometimes, we just need to add a quick fix, inject a hacky piece of code to make something work or to slightly change its behavior. What we don’t see at the first glance are the side effects. We tend to look more at whether that quick fix solved the actual problem, and we miss out the side effects it brought along with it. Tests help out with that, you get instant feedback.&lt;/p&gt;

&lt;p&gt;That’s why I am an advocate of Test Driven Development. It gets you to move those sticky pieces long before you even are done implementing a feature, and hence reduce the cost. A slight cost added is the cost of writing those tests, but you would have to write them anyway.&lt;/p&gt;

&lt;p&gt;Technical debt is inevitable in software development, and it will come around. And sometimes we need to trade off elegance for making things work, that being said, paying them off sooner will make your life a lot easier.&lt;/p&gt;</content><author><name>Dedipyaman Das</name></author><category term="Clean-Code" /><category term="Programming" /><summary type="html">Software development is cursed with an implied cost at any stage, no matter how elegant your solution looks at any point of time. The cost of fixing what you messed up. Humans write code, and code is prone to ugliness. This piles up over time and dealing with it is a challenge every team faces many times in their lifetime.</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://twodee.me/assets/blog/debt.jpg" /><media:content medium="image" url="https://twodee.me/assets/blog/debt.jpg" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Don’t fail silently, scream!</title><link href="https://twodee.me/blog/2019/09/20/errors" rel="alternate" type="text/html" title="Don’t fail silently, scream!" /><published>2019-09-20T00:00:00+00:00</published><updated>2019-09-20T00:00:00+00:00</updated><id>https://twodee.me/blog/2019/09/20/errors</id><content type="html" xml:base="https://twodee.me/blog/2019/09/20/errors">&lt;p&gt;Your business logic most certainly has the error, not someone else’s library. Use error messages, your best friend.
&lt;!--more--&gt;&lt;/p&gt;

&lt;p&gt;While working on a recent project, while I was making remote calls from a client application to a server running on the JVM everything worked until after certain number of requests to the server, the application kept failing.&lt;/p&gt;

&lt;p&gt;The server got irresponsive after too many requests, irrespective of the frequency. It just kept stopping.&lt;/p&gt;

&lt;p&gt;I was presented with a very specific and helpful message: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TSocket: timed out reading 4 bytes from {hostname}:{port}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Initially I thought I may have a very short timeout indeed, so I just bumped up the read and write timeouts to 60 seconds to see if it made any changes. It didn’t. It kept stopping after a certain number of simultaneous requests, and it wouldn’t start until I restarted the server.&lt;/p&gt;

&lt;p&gt;Something didn’t make sense, I had tested every edge case of every unit properly - yet while trying to integrate it with the rest of the modules, something simply stopped working.&lt;/p&gt;

&lt;p&gt;I kept looking at the client side, and never bothered to look at the server side - because everything seemed “just fine”. Needless to say, I failed and failed hopelessly for a week.&lt;/p&gt;

&lt;p&gt;I ended up asking the mailing list, opening a Jira ticket with a critical bug report and had long discussions with developers and users. I was surprised no one had this issue, and they couldn’t come up with a proper answer to this.&lt;/p&gt;

&lt;p&gt;Let’s just say the community support isn’t that great for this specific framework.&lt;/p&gt;

&lt;p&gt;After a week of forgetting it, working on the business logic, writing more tests I finally decided to fix this issue. I kept reproducing the bug. Then, I noticed a pattern.&lt;/p&gt;

&lt;p&gt;It wasn’t just a random number of requests - it was exactly 10 requests. It kept failing after 10 requests, which was odd. Any server should be able to handle 10 requests without any sweat. And why 10? It seemed too human-istic.&lt;/p&gt;

&lt;p&gt;For a human being to choose the number 10 (in decimal), very common. For a computer? Not so much.&lt;/p&gt;

&lt;p&gt;Maybe I wrote a magic number 10 somewhere? Probably.&lt;/p&gt;

&lt;p&gt;Then I started checking out the logs my java server was appending, and the persistence layer likes egesting the SQL queries being executed to the logs for some reason. Which ended up being very useful.&lt;/p&gt;

&lt;p&gt;For every request that I made, 2 queries were being executed. Wrongly, they shouldn’t be executed in the first place (which really wasn’t the cause of the problem, but it did help me fix the problem).&lt;/p&gt;

&lt;p&gt;So, 2 queries, multiplied by the 10 requests gave me 20 queries in total. That number seemed familiar.&lt;/p&gt;

&lt;p&gt;I started checking the connections in the server, if I had left anything open. Nope, every socket connection was closed properly.&lt;/p&gt;

&lt;p&gt;Then maybe the database was blocking my connections? 20 queries are too much? Is there a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MAX_CONNECTIONS&lt;/code&gt; limit somewhere? I was pretty sure I didn’t specify a limit like that anywhere, yet. It’s my development machine.&lt;/p&gt;

&lt;p&gt;I checked out my MySQL server with the handy command:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;mysql&amp;gt; show processlist;
+-----+------+-----------------+---------------------+---------+------+----------+------------------+
| Id  | User | Host            | db                  | Command | Time | State    | Info             |
+-----+------+-----------------+---------------------+---------+------+----------+------------------+
| 831 | root | localhost       | NULL                | Query   |    0 | starting | show processlist |
| 847 | root | localhost:34782 | Application Service | Sleep   |   54 |          | NULL             |
| 848 | root | localhost:34784 | Application Service | Sleep   |   54 |          | NULL             |
| 849 | root | localhost:34786 | Application Service | Sleep   |    2 |          | NULL             |
| 850 | root | localhost:34788 | Application Service | Sleep   |   54 |          | NULL             |
| 851 | root | localhost:34790 | Application Service | Sleep   |   54 |          | NULL             |
| 852 | root | localhost:34844 | Application Service | Sleep   |   52 |          | NULL             |
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;em&gt;AH-HA!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;My connection pooler has been spawning way too many processes.&lt;/p&gt;

&lt;p&gt;Then I went to my persistence config file specifically looking for my connection pooling config. And here it was - maximum pool size was set to, guess what? 20. All the dots fell into the their correct places, they finally connected.&lt;/p&gt;

&lt;p&gt;My connection pooling agent was spawning (or leasing) a new connection for every query I made - and that was expected. What was not expected was that the connection pooler never released them.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Then,&lt;/em&gt; I finally looked at my business logic. And guess what? All that pain for a week was for a silly, silly error.&lt;/p&gt;

&lt;p&gt;I didn’t commit or rollback the transactions I started. Uncommitted transactions don’t leave the pool, and hence for every request- I had 2 connections.&lt;/p&gt;

&lt;p&gt;As soon as I reached 20 connections, things broke. Fixing the transaction worked like a charm.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lesson Learned:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Close your connections.&lt;/li&gt;
  &lt;li&gt;Commit your transactions.&lt;/li&gt;
  &lt;li&gt;Your business logic has the error, not the library.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here’s where error messages could have been super helpful.&lt;/p&gt;

&lt;p&gt;Thrift doesn’t like to carry forward the exceptions thrown by the server to the client which it doesn’t know about.&lt;/p&gt;

&lt;p&gt;You have to explicitly tell it, &lt;em&gt;“hey, these are the exceptions that might occur if something goes wrong. Ask the client to handle them”&lt;/em&gt;. And if you don’t, well it throws a generic exception with generic messages. Not very helpful.&lt;/p&gt;

&lt;p&gt;When I check the server console, when it’s being run with Thrift, it doesn’t fail with an exception either! Java is usually super verbose, but in this case - it failed silently. Surprising.&lt;/p&gt;

&lt;p&gt;If I hadn’t run it by the server remotely, but with a custom caller within the server, maybe it would have failed while screaming something like “MaxConnectionsReachedException” (I don’t know what it really throws) with an elaborate stack trace. Now, that would have easily led me to the path I really needed to walk on.&lt;/p&gt;

&lt;p&gt;That’s why exceptions are your best friends. Just a simple error message or a stack trace could have pointed me to exactly what went wrong, but it simply wasn’t visible to me.&lt;/p&gt;

&lt;p&gt;Well, this is one of the shortcomings of my RPC framework. There are downsides to everything, but it taught me a valuable lesson:&lt;/p&gt;

&lt;p&gt;In a development environment, &lt;strong&gt;&lt;em&gt;always fail while screaming&lt;/em&gt;&lt;/strong&gt;. &lt;em&gt;NEVER&lt;/em&gt; fail silently.&lt;/p&gt;

&lt;p&gt;Also, I need to look at my business logic more and integration test more often. And you should too. Stop blaming.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Dedipyaman&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;</content><author><name>Dedipyaman Das</name></author><category term="Programming" /><summary type="html">Your business logic most certainly has the error, not someone else’s library. Use error messages, your best friend.</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://twodee.me/assets/profile.jpg" /><media:content medium="image" url="https://twodee.me/assets/profile.jpg" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Learn Programming The Right Way</title><link href="https://twodee.me/blog/2018/11/27/get-started-with-programming" rel="alternate" type="text/html" title="Learn Programming The Right Way" /><published>2018-11-27T00:00:00+00:00</published><updated>2018-11-27T00:00:00+00:00</updated><id>https://twodee.me/blog/2018/11/27/get-started-with-programming</id><content type="html" xml:base="https://twodee.me/blog/2018/11/27/get-started-with-programming">&lt;p&gt;A recent train journey inspired this blog post. As promised, albeit being late, this is the blog post on how to start programming if you are a complete beginner.&lt;/p&gt;

&lt;p&gt;This is a continuation of my post: &lt;a href=&quot;https://www.twodee.me/blog/2018/08/06/learn-programming-in-24-hours&quot;&gt;Learn Programming in 24 Hours!&lt;/a&gt;
&lt;!--more--&gt;&lt;/p&gt;

&lt;p&gt;Now here are a few gotchas about this post-&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;I do not claim to be an expert in the field.&lt;/li&gt;
  &lt;li&gt;It is not a silver bullet or a magical todo list to take you from zero to hero in less than X time.&lt;/li&gt;
  &lt;li&gt;This is not a tutorial of any kind. This post just gives a few pointers to the absolute beginner so that they can get started a bit more easily.&lt;/li&gt;
  &lt;li&gt;This post doesn’t guarantee success. This is a compilation of my experience.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;find-your-motivation&quot;&gt;Find your motivation&lt;/h1&gt;

&lt;p&gt;So when I wrote my first line of code back in 2010, I was a 10-year-old sixth-grader. I was impressed with the game Smackdown Vs Raw 2010 by WWE and THQ, especially the “Create a Wrestler” feature - which allowed players to create a fictional superstar with appearance, attributes, and moves of their liking. I wished that feature to be available in other games as well and was curious about how it was done.&lt;/p&gt;

&lt;p&gt;I wanted my own storyline and characters.&lt;/p&gt;

&lt;p&gt;So, I decided to figure it out. I grabbed my old laptop, googled “How do I make a video game?” and started hunting down ways to start making a game and ended up finding a tool called Game Maker which would allow you to create tiny little 2D video games. That was my introduction to game building. That was a good stepping stone, but I still didn’t know how to make a game with an actual storyline.&lt;/p&gt;

&lt;p&gt;I wanted control. I read more and more and found out that games need to be “programmed”. I envisioned a GTA-like open-world game with my own characters, storyline and weapons. And to do that I had to learn how to program.&lt;/p&gt;

&lt;p&gt;Enter QBASIC - my first programming language. This was being taught in my class, but I never cared for it before. Now I did. Because it meant something to me now. This is a tool I can move forward with.&lt;/p&gt;

&lt;p&gt;I started with the infamous “Hello world” program and moved on to write programs emulating a simple Quiz Game with menus and everything on the Command Line.&lt;/p&gt;

&lt;p&gt;This led me to stick in and never move away from this craft. I haven’t build a game yet, but I have moved in different directions and I am grateful to my 10 year old self for that.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So here’s the bottomline:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you don’t care about programming, you are never going to learn to program. Programming itself isn’t fun. Finding ways to solve a problem is fun. It’s the same thing as solving puzzles. No one likes adding numbers, yet people like solving Sudoku puzzles. It’s a challenge you set up for yourself. Numbers and addition is just the tool to solve that.&lt;/p&gt;

&lt;p&gt;So find yourself a problem, a motivation if you will - and start figuring out ways to solve it. One step at a time. You aren’t going to build a microservice application in one day. Start with smaller ones, make mistakes, learn from them and make a bigger one the next time.&lt;/p&gt;

&lt;h1 id=&quot;stop-reading-start-writing-iteratively-learn-from-your-experience&quot;&gt;Stop reading! Start writing iteratively, learn from your experience&lt;/h1&gt;

&lt;p&gt;As wrong that may sound, you learn to program when you program. It’s a recursive process. I have tried sitting in front of a video tutorial or reading books for hours to end up forgetting in a week or so. Reading is practically useless if you are not using it.&lt;/p&gt;

&lt;p&gt;I learn more when I write, and you should too. People call it practice. When you start writing code and compile and see it run - you are in debug mode. You try to find the flaws in your program rather than trying to remember what you did. Your brain saves that information for you.&lt;/p&gt;

&lt;p&gt;This is how it roughly works. Imagine learning to program for the first time in C.
Here’s your first piece of code that your remember seeing on a tutorial:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c&quot; data-lang=&quot;c&quot;&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Hello, world!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;You compile it and you are presented with this:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;hello.c: In function ‘main’:
hello.c:2:3: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
   printf(&quot;Hello, world!&quot;);
   ^~~~~~
hello.c:2:3: warning: incompatible implicit declaration of built-in function ‘printf’
hello.c:2:3: note: include ‘&amp;lt;stdio.h&amp;gt;’ or provide a declaration of ‘printf’
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Woah, to a beginner that’s probably very intimidating. But, if you can read english, it’s not too hard to decipher. 
Our brain just likes skipping over things.&lt;/p&gt;

&lt;p&gt;What it really says is:&lt;/p&gt;

&lt;p&gt;In function “main”, printf has been implicitly declared. The compiler doesn’t know where printf is defined. So, it’s asking you to either create a function called printf and try compiling it again OR include &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;stdio.h&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Then you recall: &lt;em&gt;Hey, I think I read about that stdio thing, maybe just include it?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You google: “How do I include &lt;stdio.h&gt; in a C program?&quot;. Some angel on Stackoverflow or some similar thread has already answered this question. And you weren't the first one to come across this!&lt;/stdio.h&gt;&lt;/p&gt;

&lt;p&gt;Then you add this line: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/code&gt; to your program. It looks somewhat like this:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c&quot; data-lang=&quot;c&quot;&gt;&lt;span class=&quot;cp&quot;&gt;#include &amp;lt;stdio.h&amp;gt;
&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Hello, world!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;It compiles successfully and you run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;./a.out&lt;/code&gt; and it works! Almost…&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;username@pc: gcc hello.c
username@pc: ./a.out
Hello, world!username@pc
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Well, we didn’t want to print the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;username@pc&lt;/code&gt; on the same line, did we? What could we be missing?&lt;/p&gt;

&lt;p&gt;It turns out, your code simply printed the text and the prompt of your shell decided to continue from that line. We need a way to print &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;RETURN&amp;gt;&lt;/code&gt; or a new line so that the cursor goes to the next line.&lt;/p&gt;

&lt;p&gt;After some research on how to move the cursor to the next line in C, you add the “\n” character to the end of the print statement.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c&quot; data-lang=&quot;c&quot;&gt;&lt;span class=&quot;cp&quot;&gt;#include &amp;lt;stdio.h&amp;gt;
&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Hello, world!&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;And you compile it once again, no errors. And you get the output:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;username@pc: ./a.out
Hello, world!
username@pc:
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;It finally works. Your brain remembered and stored it in your “Experiences” folder. Now when you write a similar program next week, you’ll immediately recall that you need to include &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;stdio.h&amp;gt;&lt;/code&gt; and add that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\n&lt;/code&gt; character.&lt;/p&gt;

&lt;p&gt;Remembering pieces of relatable experiences and failures is easier than remembering this chunk of code:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c&quot; data-lang=&quot;c&quot;&gt;&lt;span class=&quot;cp&quot;&gt;#include &amp;lt;stdio.h&amp;gt;
&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Hello, world!&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Try it out, it will almost certainly make a huge difference.&lt;/p&gt;

&lt;h1 id=&quot;add-development-tools-to-your-arsenal-and-make-life-easier&quot;&gt;Add development tools to your arsenal and make life easier&lt;/h1&gt;

&lt;p&gt;While people generally recommend you to use nothing but a simple text editor at the beginning of your programming journey, however software development is never about just one page written in one language that’s compiled by one compiler or interpreter.&lt;/p&gt;

&lt;p&gt;Get to know your tools and use them effectively. One absolute improvement in any project is the addition of version control. Pick one, git is a popular choice.&lt;/p&gt;

&lt;p&gt;Choose a proper text editor/IDE that integrates well with your programming environment. What works for me shouldn’t necessarily work for you. What works for Java shouldn’t necessarily be great for C++.&lt;/p&gt;

&lt;p&gt;I personally prefer Emacs as my default text editor to  edit configuration, write scripts, and C applications. Because of it being lightweight, fast and powerful I am more productive with it while writing command line apps.&lt;/p&gt;

&lt;p&gt;For heavyweight applications, like the ones written in Java, I prefer IntelliJ IDEA - one of the best IDEs out there. Due to Java’s verbosity, it’s often common to miss out a lot of things. IntelliJ is smart enough to keep recommending improvements and finding issues with your code even before you hit compile. It integrates well with Java build, testing and dependency management tools and makes java development a cakewalk.&lt;/p&gt;

&lt;p&gt;Then come the build tools. Choose a popularly supported build tool for your language and use that. You don’t want to manually compile every file to turn them into one final executable. Let your build tool automate and take care of that.&lt;/p&gt;

&lt;p&gt;Get a proper dependency management tool as well. Oftentimes build tools come with built in dependency management.&lt;/p&gt;

&lt;p&gt;As you move forward you’ll come across tools to unit test your application, find code coverage, add integration testing to it. All of these add to your skillset and help you write better software over time. If you don’t want your code to misbehave, you need ways to build and test them properly before you give it out to your clients.&lt;/p&gt;

&lt;h1 id=&quot;listen-to-your-tools&quot;&gt;Listen to your tools&lt;/h1&gt;

&lt;p&gt;As with the last example, the way we solved the problem was by reading the error message and understanding what it meant and acting on it. What most beginners miss out on is reading error messages.&lt;/p&gt;

&lt;p&gt;Almost every newbie who comes up to me with an issue with their code says that they are getting &lt;em&gt;“an error”&lt;/em&gt; in their code. When I ask them what the error is, they are either blank or can’t recall what it actually meant. It’s understandable, error messages from compilers aren’t always user friendly, and a lot of experienced developers face this problem too. But in most cases, at least in the beginning stages, the compilers would throw in enough pointers for you to figure out what you are doing wrong.&lt;/p&gt;

&lt;p&gt;You just need to know where to look. And that comes with experience. Compilers often print a (un)helpful message along with line numbers and function names to enable you to debug the code. One way to go about it is to read the error message line by line and interpret what that means. The language is often not aimed towards beginners, so you’ll probably need to consult a thesaurus or a dictionary if English isn’t your first language.&lt;/p&gt;

&lt;p&gt;Once you have interpreted the error into a simpler version, try finding those line numbers and function names where your compiler/interpreter is pointing you to.&lt;/p&gt;

&lt;p&gt;Then, start discarding the information you don’t need. Java often produces a stack trace with a lot of lines describing all the classes where the function was called and declared from. Discard the error messages which originated from the library or function that you didn’t write and ask yourself:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;“What did I write that caused this problem in the other library that I didn’t write?”&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Then read the filtered error message once again, and you’ll start having an idea on how to go about solving the issue. If you’ve been scratching your head for too long, then you may go ahead and google that filtered error message. Chances are, someone already had that issue.&lt;/p&gt;

&lt;p&gt;Being able to read error messages and interpreting its meaning is as important as being able to expressing your thoughts in your code.&lt;/p&gt;

&lt;p&gt;Your code is you trying to tell the computer what to do. The error message is what the computer telling you that it can’t do what you asked it to do, because you did something wrong or it doesn’t understand how to do it. This more you improve working with this feedback mechanism, the better you get.&lt;/p&gt;

&lt;p&gt;You need to be able to talk to your computer very clearly to be able to write applications that solve your problem.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Programming is a two way communication.&lt;/strong&gt;&lt;/p&gt;

&lt;h1 id=&quot;write-programs-a-lot-of-them&quot;&gt;Write programs, a lot of them!&lt;/h1&gt;

&lt;p&gt;Not writing code is by far one of the biggest problem with students I have met in my university life. Students learn a new language, the grammar and the semantics and just move on with the next cool thing they find without actually trying to stick with one thing and making something useful. They put it in their resume and move on with their lives.&lt;/p&gt;

&lt;p&gt;The only way to get better at writing programs, is to write more programs that solve different kinds of problems. Doing the same thing over and over again isn’t going to make much of a difference. You need to find new challenges and solve them every day. One good way to keep track of it is using Github contributions. Looking at the green boxes will help you understand if you are actually improving or not.&lt;/p&gt;

&lt;p&gt;The greener your page is, the more you have been improving. If it’s been greying out, this is your wake up call. Yes, there are days when you don’t feel like it. And it’s fine to take a break every once in a while.&lt;/p&gt;

&lt;p&gt;On average, I write and delete about 150-300 lines of meaningful code everyd ay. When I say meaningful, it means that the code actually does something useful and not just for the sake of keeping my Github profile green.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If there’s one thing that you can to pick from this list, this is the one.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Make projects! Stop watching those video tutorials about that fancy new technology. Make something first and keep improving on it.&lt;/p&gt;

&lt;p&gt;I have come across individuals who have been “course hopping” from one course to another. One minute they learn python, the other minute they learn Android. And I am yet to see anything useful come out of them. Don’t be a course hopper. If you can’t commit to a particular online course (I can’t, I am too impatient), just work on a project.&lt;/p&gt;

&lt;p&gt;If you want to stick to reading about technologies and how they work and not implement them and see them actually work - maybe engineering isn’t for you. You can stick to academia instead. And there’s nothing wrong in that. Not everyone in the computer science community needs to be a great programmer. It’s just a subset.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Experience is a bigger teacher than training.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Dedipyaman&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;</content><author><name>Dedipyaman Das</name></author><category term="Programming" /><category term="Beginners" /><summary type="html">A recent train journey inspired this blog post. As promised, albeit being late, this is the blog post on how to start programming if you are a complete beginner. This is a continuation of my post: Learn Programming in 24 Hours!</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://twodee.me/assets/profile.jpg" /><media:content medium="image" url="https://twodee.me/assets/profile.jpg" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">How Pycon India 2018 changed the way I see things</title><link href="https://twodee.me/blog/2018/10/29/pycon" rel="alternate" type="text/html" title="How Pycon India 2018 changed the way I see things" /><published>2018-10-29T00:00:00+00:00</published><updated>2018-10-29T00:00:00+00:00</updated><id>https://twodee.me/blog/2018/10/29/pycon</id><content type="html" xml:base="https://twodee.me/blog/2018/10/29/pycon">&lt;p&gt;I was all set up, I grabbed my backpack, put my laptop in and ready to go. We reached the railway station by 4 PM and had the train at 5:30 to Hyderabad. I was excited. Firstly because I was taking a few days off college after 3 months, secondly I am going to visit this Pycon thing which I heard about from my friend &lt;a href=&quot;http://hellozee.me&quot; target=&quot;_blank&quot;&gt; Kuntal &lt;/a&gt; a few months back.
&lt;!--more--&gt;&lt;/p&gt;

&lt;p&gt;I originally planned to get the student tickets, but got caught up with the schedule and had to get the regular ones. &lt;em&gt;It’s alright&lt;/em&gt;, I thought, &lt;em&gt;I just hope the experience (or the food) makes up for it&lt;/em&gt;. We reached Hyderabad by 12 midnight, and stayed at my roommate’s place. Crashed on the bed by 1. I was excited and couldn’t sleep for a while. But my body gave in to the fatigue of the travel.&lt;/p&gt;

&lt;h3 id=&quot;day-1&quot;&gt;Day 1&lt;/h3&gt;

&lt;p&gt;I dressed to my best in the next morning. We took a cab, I was enjoying the Hyderabadi streets and traffic. As we approached &lt;a href=&quot;http://www.hicc.com&quot; target=&quot;_blank&quot;&gt;HICC&lt;/a&gt;, I saw the Pycon posters - enter nervousness. Amongst all the excitement to meet developers with similar interests, I realized:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;I am not a regular Python developer.&lt;/li&gt;
  &lt;li&gt;This is my first meet up and I haven’t done anything like this before.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I wasn’t very sure how I’d connect to people when the one thing that brought them together - &lt;strong&gt;Python&lt;/strong&gt; - wasn’t my go-to language for anything. I barely ever used python. Even when I had to work on a project with a Raspberry Pi, I wrote the entire application in Java and ran a few tiny python scripts on top of it, but that’s it.&lt;/p&gt;

&lt;p&gt;Upon reaching the beautiful HICC, I saw people, all sorts of people walking around with their Pycon IDs and clicking photos, talking to each other. Nothing unusual. You see that everyday.&lt;/p&gt;

&lt;p&gt;But that was not a regular crowd.&lt;/p&gt;

&lt;p&gt;That was a passionate group of people who loved doing what they did. They were developers of all ages, all races. Some of them came from far off places. They had been united by one common interest - writing software, making a difference and sharing ideas.&lt;/p&gt;

&lt;p&gt;I was thrilled and scared at the same time. &lt;em&gt;What if I am not good enough? What if they don’t accept me as one of them? But damn it, I paid for this and I travelled far enough.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I reached the counter, looking around at people with clothes that proudly said that they were developers. A Hacktoberfest T-shirt here, a Linux t-shirt there. I got my ID, met Kuntal and grabbed my goodies and stickers(!).&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/pycon/armin.jpeg&quot; alt=&quot;Armin Ronacher at Pycon 2018&quot; /&gt;&lt;/p&gt;
&lt;div class=&quot;alt&quot;&gt;Armin Ronacher at Pycon 2018&lt;/div&gt;

&lt;p&gt;I attended the first Keynote speech by &lt;strong&gt;Armin Ronacher&lt;/strong&gt;, &lt;em&gt;the creator of Flask!&lt;/em&gt; That is celebrity level. He talked about how the Python and the Rust community evolved and what the Python community can learn from the Rust community.&lt;/p&gt;

&lt;p&gt;After the amazing speech, I turned to the audience and I saw hundreds and hundreds of developers. Young and old. It was overwhelming.&lt;/p&gt;

&lt;p&gt;I started visiting the stalls. This was my chance. &lt;em&gt;Connect&lt;/em&gt;, I said to myself. I found out about the job opportunities. I met some really cool people in the process. I visited the open source communities and worked some programming contests and quizzes.&lt;/p&gt;

&lt;p&gt;I realized I was wrong. The community made me feel welcome at home. It felt like I am a part of it. No more an alien. I was one of them.&lt;/p&gt;

&lt;p&gt;I went to the &lt;strong&gt;Pyladies&lt;/strong&gt; and the &lt;strong&gt;LinuxChix India&lt;/strong&gt; community stalls and that was the first time I met so many lady programmers who were genuinely passionate about it. They have been doing a great job encouraging more women into technology.&lt;/p&gt;

&lt;p&gt;Then, there was the &lt;a href=&quot;http://fossasia.org&quot; target=&quot;_blank&quot;&gt;FOSSASIA&lt;/a&gt; stall. I met &lt;strong&gt;Mario Behling&lt;/strong&gt; and his team demonstrating the &lt;em&gt;PSLAB&lt;/em&gt; there. They also organized &lt;strong&gt;Jugaad fest&lt;/strong&gt;, &lt;strong&gt;Codeheat&lt;/strong&gt; and a lot more! I couldn’t believe that I was talking to the founder of &lt;strong&gt;FOSSASIA&lt;/strong&gt;. They were making wonderful stuff, open for all and yet so down to earth and genuine.&lt;/p&gt;

&lt;p&gt;In the PSF stall, I was curious about this &lt;strong&gt;GitCoin&lt;/strong&gt; thing on the stickers, and out of nowhere a guy with glasses - who I later found out was Kushal Das- stepped in and said, &lt;em&gt;“Gitcoin is about paying developers for contributing to open source. Open source is all about money. If anyone says otherwise, DON’T BELIEVE THEM!”&lt;/em&gt; I wasn’t so sure how to react for a moment or two. This was interesting!&lt;/p&gt;

&lt;p&gt;I kept hopping stalls for a while and came &lt;strong&gt;lunchtime&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Pycon India 2018 had one of the best buffets I have ever had. All the variety, all the freshly made stuff, all for you. It couldn’t have been better.&lt;/p&gt;

&lt;p&gt;I attended a few more speeches, learnt a lot about optimzing applications, architecting solutions efficiently and how software can create a huge impact on the society- with the power of open source and collaboration. I got the chance to listen to the lightning talks after that.&lt;/p&gt;

&lt;p&gt;I was amazed to see what people were doing with software!&lt;/p&gt;

&lt;h3 id=&quot;day-2&quot;&gt;Day 2&lt;/h3&gt;

&lt;p&gt;I came back excited this time, attended the keynote by &lt;strong&gt;Travis Oliphant&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I couldn’t believe who stood before my eyes. Although I am not a regular Pythonista. I have heard about and seen &lt;em&gt;Numpy, Scipy and Anaconda&lt;/em&gt; in action. The guy who created them all stood before me.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/pycon/travis.jpeg&quot; alt=&quot;Travis Oliphant's keynote speech at Pycon India 2018&quot; /&gt;&lt;/p&gt;
&lt;div class=&quot;alt&quot;&gt;Travis Oliphant's keynote speech at Pycon India 2018&lt;/div&gt;

&lt;p&gt;He shared some wonderful insights on how things changed over the years, how the community grew and how he evolved with it. He shared his journey from being a scientist to be the founder of Quansight. And the importance of family and relationships.&lt;/p&gt;

&lt;p&gt;I later had the chance to meet him personally. He gave me some valuable insights on how to manage time effectively and how to think while building something. How to look for certain things and going into the details.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/pycon/with-travis.jpeg&quot; alt=&quot;Travis Oliphant and Dedipyaman Das at Pycon India 2018&quot; /&gt;&lt;/p&gt;
&lt;div class=&quot;alt&quot;&gt;Travis Oliphant and Dedipyaman Das&lt;/div&gt;

&lt;p&gt;So, I have met someone who literally changed the lives of millions. Something to be taken off my bucket list.&lt;/p&gt;

&lt;p&gt;I later got the chance to meet Armin Ronacher as well who shared some great tips about what and what not to worry about while building web applications.&lt;/p&gt;

&lt;p&gt;Although I wasn’t a Pythonista, it all made sense to me!&lt;/p&gt;

&lt;p&gt;Hopped a few more stalls, met few people at the &lt;strong&gt;ILUGD&lt;/strong&gt;. Everyone around me were friendly creatures. Open minded. This was all overwhelming.&lt;/p&gt;

&lt;p&gt;The conference of Pycon India was concluded with &lt;strong&gt;Carol Willing&lt;/strong&gt;, core developer of Jupyter and CPython, and her inspiring speech about the future of Python. It was wonderful. She took us back in time through the entire conference once again. Recaped the moments we had in the conference.&lt;/p&gt;

&lt;p&gt;After attending the lightning talks, my feet felt heavy. I didn’t want to go back. After all of this, this is where I wanted to be. I had two more days left.&lt;/p&gt;

&lt;h3 id=&quot;day-3-and-4--the-sprints&quot;&gt;Day 3 and 4 : The sprints&lt;/h3&gt;

&lt;p&gt;The developer sprints helped me connect, work with the community and get to know how open source works better. Although, I have been an open source contributor for sometime, the dev sprints really gave me a much needed push.&lt;/p&gt;

&lt;p&gt;I have been slacking without motivation for a month before that. Not having written any code for a month, I wasn’t very confident. I just wanted to make sure that I didn’t embarass myself.&lt;/p&gt;

&lt;p&gt;I joined the Jupyter team with Carol Willing and Miss Madhu mentoring the developers for iPywidgets and other Jupyter applications. I decided to work on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jupyter/qtconsole&lt;/code&gt;, since I had worked on some Qt applications, albeit they were on C++.&lt;/p&gt;

&lt;p&gt;I started reading some code and documentation. I was surprised how fast I could understand whatever was happening inside. Python is a really easy and welcoming language I figured.&lt;/p&gt;

&lt;p&gt;I went up to Carol, sat next to her and she gave me some nice pointers to get started off with it. I sat with a developer with &lt;em&gt;41 years of experience&lt;/em&gt; and few other developers and coded.&lt;/p&gt;

&lt;p&gt;Wait, this is what I have been aspiring to do for the last 8 years of my programming career!&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/pycon/sprint.jpeg&quot; alt=&quot;Developing with Jupyter and Carol&quot; /&gt;&lt;/p&gt;
&lt;div class=&quot;alt&quot;&gt;Developing with Jupyter and Carol&lt;/div&gt;

&lt;p&gt;This was dream coming true.&lt;/p&gt;

&lt;p&gt;I got my first pull request accepted and merged by Carol to qtconsole. And the feeling was wonderful.&lt;/p&gt;

&lt;p&gt;This, this changed everything. I finally got a reason to start programming once again. I started looking out for more probable bug fixes, documentation changes that could help the projects.&lt;/p&gt;

&lt;p&gt;I even got the chance to talk to her on a human level. She shared her story - how things began from her home near IBM when she started coding in her fifth grade. From Basic to Processing to Python. The long way she has come since then.&lt;/p&gt;

&lt;p&gt;We had lunch together, &lt;em&gt;on the floor&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;And we clicked selfies!&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/pycon/with-carol.jpeg&quot; alt=&quot;Dedipyaman's selfie with Carol Willing&quot; /&gt;&lt;/p&gt;
&lt;div class=&quot;alt&quot;&gt;Dedipyaman's selfie with Carol Willing&lt;/div&gt;

&lt;p&gt;I had so much to learn from this woman! This is how my heroes look like.&lt;/p&gt;

&lt;p&gt;After two days of dev-sprints (which also helped me grab a chance for Hacktoberfest t-shirts), I had to return to my college.&lt;/p&gt;

&lt;p&gt;Although, I did want more. I was content. I was happy. This has changed me. This is what open source is all about. It’s about creating connections, which leads to wonderful results.&lt;/p&gt;

&lt;p&gt;These days I have been writing code and contributing to open source almost everyday.&lt;/p&gt;

&lt;p&gt;I have met people who have impacted the lives of millions. They talked to people for hours. Sharing ideas, thoughts, experiences. They weren’t bothered. They seemed happy to share it all. I don’t know how they do it, but they did.&lt;/p&gt;

&lt;p&gt;I would come back here hundred more times if I could. But I guess I won’t be alive for that long. Alas.&lt;/p&gt;

&lt;p&gt;I couldn’t have asked for more. Thank you Pycon. For the t-shirt, the goodies, the food and the experience.&lt;/p&gt;

&lt;p&gt;If you are a programmer who hasn’t visited Pycon yet, do yourself a favor, visit Pycon. The experience would be worth remembering and sharing. I will see you there next year!&lt;/p&gt;

&lt;p&gt;I realized, it was never just about Python. &lt;em&gt;It has always been about the &lt;strong&gt;community&lt;/strong&gt;&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Dedipyaman&lt;/em&gt;&lt;/p&gt;</content><author><name>Dedipyaman Das</name></author><category term="Experiences" /><summary type="html">I was all set up, I grabbed my backpack, put my laptop in and ready to go. We reached the railway station by 4 PM and had the train at 5:30 to Hyderabad. I was excited. Firstly because I was taking a few days off college after 3 months, secondly I am going to visit this Pycon thing which I heard about from my friend Kuntal a few months back.</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://twodee.me/assets/pycon/travis.jpeg" /><media:content medium="image" url="https://twodee.me/assets/pycon/travis.jpeg" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">The engineering addiction</title><link href="https://twodee.me/blog/2018/09/09/side-effects" rel="alternate" type="text/html" title="The engineering addiction" /><published>2018-09-09T00:00:00+00:00</published><updated>2018-09-09T00:00:00+00:00</updated><id>https://twodee.me/blog/2018/09/09/side-effects</id><content type="html" xml:base="https://twodee.me/blog/2018/09/09/side-effects">&lt;p&gt;When I decided to leave Facebook and Instagram for good, more than a year back, I had a valid point- social media was getting toxic. Unbearable. It was growing heavy on me.&lt;/p&gt;

&lt;p&gt;I was having trouble dealing with my priorities, living in a world of lies, where every other person was happy. Their smiles on social media would brighten up anyone’s day.&lt;/p&gt;

&lt;p&gt;They had the perfect life. I was confused.&lt;/p&gt;

&lt;p&gt;How can I be not so happy? Why doesn’t my profile reflect the happiness that they do? 
&lt;!--more--&gt;&lt;/p&gt;

&lt;p&gt;Well, then I decided to check my own profile, and guess what?&lt;/p&gt;

&lt;p&gt;I was happy too! At least my profile made it look like I was.&lt;/p&gt;

&lt;p&gt;Social media is not what you are but what you make of it.&lt;/p&gt;

&lt;p&gt;I was going through a range of emotions, not all at once. It wasn’t a bombshell dropped on me. It was more like poetry. Taking me through different facets, gradually progressing while slowly pouring on me with one central idea, which wasn’t so easy to decipher- just like poems are.&lt;/p&gt;

&lt;p&gt;At one point when, I figured where I break. I found my tripping point.&lt;/p&gt;

&lt;p&gt;I had mixed emotions. I had this idea, &lt;em&gt;“what would happen if the fancy online presence I made for myself is not there when I would need it the most? Because &lt;strong&gt;someday&lt;/strong&gt; I will come up with this &lt;strong&gt;world-changing&lt;/strong&gt; thing that would need all the exposure I can give it to fly”&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Naturally, the &lt;strong&gt;someday&lt;/strong&gt; never came. It never does.&lt;/p&gt;

&lt;p&gt;With the gradual beating from life’s poetry, I gave up the thought of the one magical idea of the future, the what-if. I stopped using social media. I deleted Facebook, Instagram.&lt;/p&gt;

&lt;p&gt;I went complete incognito.&lt;/p&gt;

&lt;p&gt;I pulled myself out of the social media circle. I have grown a lot since then. I worked on a dozen new projects that helped me skill up, I came out of my comfort zone and wrote some applications, libraries that helped me grow in ways I couldn’t have imagine a year back. I have gained some valuable experience and I have learnt to communicate my ideas.&lt;/p&gt;

&lt;p&gt;I didn’t need to care about whose birthday it was, or who just bought a fancy new iPhone. No more needing validation from pointless internet points in the forms of likes from people I barely cared about, but I pretended I did.&lt;/p&gt;

&lt;p&gt;I eventually joined some of the essential social media platforms which I do need for communicating with people for work. I figured LinkedIn was a great medium to make great connections on a professional level, Twitter became a nice place to get updates from my favorite things to follow and I started checking my email instead of Whatsapp messages.&lt;/p&gt;

&lt;p&gt;With all of these happening, I went full productive-workaholic mode. I needed to make something everyday. Make some significant change. Nothing in the world gave me more pleasure than making that one bit of code work. It grew on me. I wanted to acheive something everyday.&lt;/p&gt;

&lt;p&gt;I slowly got addicted to productivity. It was my drug. Then came real life, and disappointments. The thing is, &lt;strong&gt;addiction is bad&lt;/strong&gt;. Period. Even if it’s something good you are getting addicted to, if you don’t have enough flexibility in your mindset, you tend to disappoint yourself. Every single day, when I wouldn’t get something significant done - I would be sad. I would go to bed not happy with myself, introspecting everything wrong that I did today and hoping to have a better tomorrow.&lt;/p&gt;

&lt;p&gt;This thing never worked. I have this problem, and I am sure a lot of others do too, if I am not productive throughout the entire day - I would have this literal heat passing from my feet to my body and I can feel it very well. It happens at night, usually after my dinner. My feet would turn cold, my palms would be sweaty and I would have this sadistic anger within me, that I almost want to break everything I have. And then, my friend who lives inside me, wakes up. A little demonic angel. This guy, comes up with a &lt;em&gt;brilliant&lt;/em&gt; idea!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Look, you wasted the entire day, you didn’t acheive what you wanted to, and what you could have. You have 3 more hours of uptime left, and you will be weak and angry for this period. Why don’t you just sleep now, and I &lt;strong&gt;guarantee&lt;/strong&gt; you, tomorrow is going to be the day when you change the world?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The guy sounds pretty damn reasonable. After all, what good can I do in the last 3 hours of the day when I couldn’t do anything at all the entire day? This, when coupled with procrastination would be lethal. The panic monkey visits me occasionally, I get productive in the last moments sometimes. Sometimes I don’t. This, when continued for a week or more - brings in a new thought process. A scary one.&lt;/p&gt;

&lt;p&gt;I would get more sadistic and more destructive. Every ounce of motivation would be crippled, and I would crave the social life I once had. Motivation is the hardest to find at that point.&lt;/p&gt;

&lt;p&gt;Focus and attention are two of the hardest earned things in my life. At the end, obsession towards productivity turned on me. The mind needs to be flexible enough to handle all the kind of curves life would throw at you. Perhaps the best way is to hustle, take every day as a different one. Things change, situations change. If you need to find a motivation, do new things and find that trigger.&lt;/p&gt;

&lt;p&gt;Letting it grow, perhaps, isn’t the best option. Growing how to deal with it maybe is. It works for me at least. When I changed my mindset- to live one day at a time. I stopped looking for how I wasn’t productive so long, but what can I do in the next one hour? Maybe one tiny refactoring could help.&lt;/p&gt;

&lt;p&gt;It turned out, I wasn’t as disappointed on myself as I would have been. I could do more. The motivation was to do one tiny thing instead of making a big change everyday. This worked out for me, pretty well.&lt;/p&gt;

&lt;p&gt;Although I still have downtimes, I have low days. I know how to deal with them now. It’s easier when you do have a bigger goal in mind, but you take one small atomic step at a time.&lt;/p&gt;

&lt;p&gt;Go easy on yourself. Life doesn’t need to be so strict. We don’t have to be a railway track when life itself is more like a curvy rocky mountain way.&lt;/p&gt;

&lt;p&gt;Make atomic changes, atomic commits.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Dedipyaman&lt;/em&gt;&lt;/p&gt;</content><author><name>Dedipyaman Das</name></author><category term="Social-Life" /><summary type="html">When I decided to leave Facebook and Instagram for good, more than a year back, I had a valid point- social media was getting toxic. Unbearable. It was growing heavy on me. I was having trouble dealing with my priorities, living in a world of lies, where every other person was happy. Their smiles on social media would brighten up anyone’s day. They had the perfect life. I was confused. How can I be not so happy? Why doesn’t my profile reflect the happiness that they do?</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://twodee.me/assets/profile.jpg" /><media:content medium="image" url="https://twodee.me/assets/profile.jpg" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Learn programming in 24 hours!</title><link href="https://twodee.me/blog/2018/08/06/learn-programming-in-24-hours" rel="alternate" type="text/html" title="Learn programming in 24 hours!" /><published>2018-08-06T00:00:00+00:00</published><updated>2018-08-06T00:00:00+00:00</updated><id>https://twodee.me/blog/2018/08/06/learn-programming-in-24-hours</id><content type="html" xml:base="https://twodee.me/blog/2018/08/06/learn-programming-in-24-hours">&lt;p&gt;Every now and then I come across Youtube videos or ads along the lines of - “Learn programming in 24 hours!” or “Learn React.js in a week”. What’s the rush?
&lt;!--more--&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Programming is a craft.&lt;/strong&gt; And like any form of craft, you don’t master it in 24 hours. You don’t master it in 24 days. Heck, you might not even master it in 24 years.&lt;/p&gt;

&lt;p&gt;So, how do you really get there? Or do you even get there?&lt;/p&gt;

&lt;p&gt;The magic sauce to this recipe is- &lt;em&gt;*drumroll*&lt;/em&gt; &lt;strong&gt;practice&lt;/strong&gt;. Ah, the glaringly obvious word.. What a disappointment, right? But really, think about it. How did the best programmer, muscian, driver, carpenter or anyone who you’d consider an expert &lt;em&gt;get there&lt;/em&gt;?&lt;/p&gt;

&lt;p&gt;Was it because they found some wonderful resource online or a youtube tutorial that helped them attain Nirvana? Did they learn it in 24 or 36 hours?&lt;/p&gt;

&lt;p&gt;They started off just like any other kid who wants to ride a bicycle for the first time. By &lt;em&gt;&lt;strong&gt;doing&lt;/strong&gt;&lt;/em&gt; it. You didn’t read a manual on how to ride a bicycle in 24 hours when you were young, did you?&lt;/p&gt;

&lt;p&gt;As a kid does, they tried out something that intrigued them. And like in most cases, they fell. They failed. &lt;em&gt;Failure is an important step towards success.&lt;/em&gt; If you don’t know the taste of failure, you’d never know the joy of winning. And chances are, you will never win.&lt;/p&gt;

&lt;p&gt;I understand, we are humans. We are greedy and we don’t like to risk it. Most of the undergrad students in my college took CS simply because &lt;em&gt;“it has a good scope”&lt;/em&gt; or &lt;em&gt;“it’s trending in the market now”&lt;/em&gt; or even for outrageous reasons like &lt;em&gt;“I got great marks in my XYZ exam which involved math, physics and chemistry- so I should take CS because that’s what toppers do”&lt;/em&gt;. I am not saying that these are wrong motivations for joining CS, you gotta feed yourself, right? But when you &lt;strong&gt;do&lt;/strong&gt; join CS, and then you &lt;strong&gt;DO NOT&lt;/strong&gt; like the subject and you start memorizing code snippets, googling “learn C++ in 24 hours” to pass the test tomorrow, that’s where you are doing it wrong.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;YOU DO NOT LEARN PROGRAMMING IN 24 HOURS.&lt;/strong&gt;  Repeat after me- &lt;strong&gt;YOU DO NOT LEARN PROGRAMMING IN 24 HOURS.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Sure, you can learn a few keywords, variable assignments, conditional statements, loops in a couple of hours. But that’s not remotely close to what programming really stands for. You are memorizing a &lt;strong&gt;language&lt;/strong&gt; not learning how to &lt;strong&gt;program&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;To be a programmer, to learn programming you have to start from the very beginning, go into the child curious mode and start asking the silliest questions that come to your mind. And then you start programming, with even the tiniest bit of information you gathered uptil now. You apply everything you learnt. You have to see it work and understand why it works. And then you learn a bit more, and you write a bit more. And you keep doing it. For a day. A week. A month. A year. A decade. A lifetime.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;“Now take your best rhyme, outdo it, now do it a thousand times” - Eminem&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You know the difference between a real software engineer at google and a wannabe &lt;em&gt;hacker boyz&lt;/em&gt; straight out of college? The software engineer wrote thousands, maybe millions of lines of code in his or her life while our four year degree &lt;em&gt;hackerz&lt;/em&gt; has been on youtube for far too long and installed Kali Linux. The skillful engineer is humble and knows their limitations. They keep learning and they don’t stop. The more they learn about something, the more they know how much they don’t know.&lt;/p&gt;

&lt;p&gt;The only way to learn programming is by programming. That’s a recursive process and this is how every other form of craft or engineering is meant to be. You don’t learn if you don’t build enough.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;“The master has failed more times than the beginner has even tried.” - Stephen McCranie&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Over the years, I have been through a lot of phases on this journey to be a software developer. I have had the opportunity to meet some brilliant people and some downright desperate “coders”. The biggest differentiating factor between these two were the amount of time and effort each group put on themselves before they started calling them “programmers”. You need to write a lot of programs to become a good programmer.&lt;/p&gt;

&lt;h3 id=&quot;so-you-want-to-become-a-webandroiddesktop-appxyz-developer&quot;&gt;So, you want to become a web/android/desktop app/xyz developer?&lt;/h3&gt;

&lt;p&gt;Here’s what you gotta do. Go out there, find a cool looking website, app or whatever, check out why it looks as such and draw a picture in your mind. This is your project for the next summer. Oh wait. Nope. &lt;em&gt;“for the next summer”&lt;/em&gt; - very very bad suggestion. You DO NOT wait for the next summer. You do it now. Like, right now. You find a resource online for free, you follow it and you build something.&lt;/p&gt;

&lt;p&gt;Don’t worry about good or bad practices. Don’t worry about how the end product looks. Your first piece of big project is going to be crappy. So is your next project. So is the next one. But that’s going to be relatively less crappier than every former version. It’s pretty common in the software business to write pretty code now and curse ourselves six months later for writing such a huge unmaintainable piece of crap. And that’s okay. You are most likely to fail on the very first project, and it’s okay.&lt;/p&gt;

&lt;p&gt;Programming is not something you do in a day or a week. You take your time, commit to a task and keep improving everyday.&lt;/p&gt;

&lt;h3 id=&quot;so-how-do-i-really-get-started&quot;&gt;So how do I &lt;em&gt;really&lt;/em&gt; get started?&lt;/h3&gt;

&lt;p&gt;My next blog post will contain some tips and pointers. Just a few hints to get you started. It won’t explain why this framework is better than the other or which language is the best, but it will give you a slight heads up on what to expect and what to avoid. I learnt from my mistakes, you probably don’t want to make the same mistakes that are easily avoidable and just downright silly. I will let you make your own sets of mistakes. Tune in to my next post to &lt;em&gt;learn programming in 10 years&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Here is a link to the continuation of this post where I write about how I approached programming: &lt;a href=&quot;https://twodee.me/blog/2018/11/27/get-started-with-programming&quot;&gt;Learn Programming the Right Way&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PS.:&lt;/strong&gt; I prefer refering to what I do as “Engineering”. Programming is just one part of what I do, one piece of the puzzle.&lt;/p&gt;

&lt;p&gt;Additional reads:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://norvig.com/21-days.html&quot;&gt;Teach yourself programming in 10 years - Peter Norvig&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Dedipyaman&lt;/em&gt;&lt;/p&gt;</content><author><name>Dedipyaman Das</name></author><category term="Programming" /><category term="Beginners" /><summary type="html">Every now and then I come across Youtube videos or ads along the lines of - “Learn programming in 24 hours!” or “Learn React.js in a week”. What’s the rush?</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://twodee.me/assets/profile.jpg" /><media:content medium="image" url="https://twodee.me/assets/profile.jpg" xmlns:media="http://search.yahoo.com/mrss/" /></entry></feed>