<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Stephan Tromer on Medium]]></title>
        <description><![CDATA[Stories by Stephan Tromer on Medium]]></description>
        <link>https://medium.com/@stephantromer?source=rss-f58432861889------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*hPMxSEPSGJbpcfU5LAuLHg.jpeg</url>
            <title>Stories by Stephan Tromer on Medium</title>
            <link>https://medium.com/@stephantromer?source=rss-f58432861889------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 22:00:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@stephantromer/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Online (AWS) Proctored Exams Are Terrible]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@stephantromer/online-aws-proctored-exams-are-terrible-db00e72e4d2a?source=rss-f58432861889------2"><img src="https://cdn-images-1.medium.com/max/1200/1*LUflNx63mWNH54-ot5T3AA.jpeg" width="1200"></a></p><p class="medium-feed-snippet">Let me tell you why online proctored exams using Pearson VUE are terrible.</p><p class="medium-feed-link"><a href="https://medium.com/@stephantromer/online-aws-proctored-exams-are-terrible-db00e72e4d2a?source=rss-f58432861889------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@stephantromer/online-aws-proctored-exams-are-terrible-db00e72e4d2a?source=rss-f58432861889------2</link>
            <guid isPermaLink="false">https://medium.com/p/db00e72e4d2a</guid>
            <category><![CDATA[aws-exam]]></category>
            <category><![CDATA[pearson-vue]]></category>
            <category><![CDATA[online-exam]]></category>
            <dc:creator><![CDATA[Stephan Tromer]]></dc:creator>
            <pubDate>Wed, 16 Mar 2022 12:16:09 GMT</pubDate>
            <atom:updated>2022-03-16T12:16:09.011Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[My dev setup 2022]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@stephantromer/my-dev-setup-2022-aa4328044699?source=rss-f58432861889------2"><img src="https://cdn-images-1.medium.com/max/766/0*GC1oOwC_sfIJSCqc.png" width="766"></a></p><p class="medium-feed-snippet">As a developer, I am continually trying to make my work easier and more automated. This includes both software and hardware, but also the&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@stephantromer/my-dev-setup-2022-aa4328044699?source=rss-f58432861889------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@stephantromer/my-dev-setup-2022-aa4328044699?source=rss-f58432861889------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa4328044699</guid>
            <category><![CDATA[terminal]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[workflow]]></category>
            <dc:creator><![CDATA[Stephan Tromer]]></dc:creator>
            <pubDate>Thu, 13 Jan 2022 11:07:29 GMT</pubDate>
            <atom:updated>2022-01-13T11:07:29.019Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[How to handle poison pills in Spring Kafka?]]></title>
            <link>https://medium.com/@stephantromer/how-to-handle-poison-pills-in-spring-kafka-a017d705a541?source=rss-f58432861889------2</link>
            <guid isPermaLink="false">https://medium.com/p/a017d705a541</guid>
            <category><![CDATA[kafka]]></category>
            <dc:creator><![CDATA[Stephan Tromer]]></dc:creator>
            <pubDate>Fri, 16 Jul 2021 13:14:47 GMT</pubDate>
            <atom:updated>2021-07-16T13:14:47.230Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dxuU6Ibja1sqNXLl.jpg" /></figure><p>Modern applications are increasingly build using smaller components that communicate with each other using events, a so-called <a href="https://medium.com/microservicegeeks/introduction-to-event-driven-architecture-e94ef442d824">event-driven architecture</a>. Event-driven architectures have three key components: event producers, event broker, and event consumers. It is important that the consumers can consume the events the producer has produced. Whenever this is not the case and you’re not ready for this scenario a single event can cause your systems to halt. Such an event is a poison pill.</p><p>In this blog I will discuss what exactly are poison pills, how they occur and how to deal with them. I also created an example project where you can see the effects of a poison pill and what you can do to handle them.</p><h3>Serialization and deserialization</h3><p>To understand what a poison pill is and how they occur, we first need to learn what serialization and deserialization is exactly. <a href="https://en.wikipedia.org/wiki/Serialization">Wikipedia</a> has in my opinion one of the best explanations:</p><p><em>Serialization is the process of converting an object state into a format (series of bytes) that can be stored or transmitted and reconstructed later possibly in a different computer environment. The opposite operation, converting a series of bytes to an object state, is called deserialization.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/291/0*Ji2K8cFgfXDJe_Bu.png" /></figure><p>In the context of Kafka, serialization is used to convert a Java object into a byte array that is subsequently produced by the producer to a topic. Deserialization is again used in the opposite manner, consuming a series of bytes from a topic and converting it into a Java object. Both the key and value of the record are serialized and later when consumed deserialized.</p><h3>What is a poison pill</h3><p>A poison pill is a record that has been produced to a Kafka topic, but cannot be consumed by a consumer, regardless of how many times it is attempted. The three most likely causes of a poison pill are corrupted records, an error during the deserialization of the record or a schema mismatch. A <a href="https://avro.apache.org/docs/current/">schema</a> is used to describe the format of the produced and consumed events. If a consumed event does not adhere to the schema the consumer will return an error as well. Deserialization errors and schema mismatches are the most likely to occur. In my time using Kafka for the last two years, I have never seen a corrupt record, but I have seen quite some deserialization errors and schema mismatches. I never caused any of them of course😉.</p><h3>Cause of a poison pill</h3><p>Like I explained in the previous paragraph, corrupted records could be the cause of a poison pill. Luckily only in some rare circumstances it can happen that a corrupted record is placed in a Kafka topic. A network hiccup is an example of what can result in a corrupted record. If a bit is flipped during transport the <a href="https://en.wikipedia.org/wiki/Checksum">CRC checksum</a> will fail and the data can no longer be trusted. Since corrupt records do not occur often and can have many peculiar explanations, this blog will not focus on dealing with corrupted records. The remainder of this blog will focus on deserialization errors instead. Deserialization errors and schema mismatches can be used interchangeable in the context of a poison pill and the same solutions can be used to handle schema mismatches. Whenever you read deserialization error, you can think of a schema mismatch as well.</p><p>If the producer and consumer are using compatible serializers and deserializers everything will work as expected. In the image below an example of compatible JSON serializers and deserializers is given. The poison pill scenario is in this case avoided.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/0*0rnPKbUyjh_dvW3z.png" /></figure><p>Deserialization errors will occur when producers and consumers have incompatible serializers and deserializers. Both the key and value deserializers should be compatible in order to prevent deserialization errors. In the example below the producer is using a StringSerializer while the consumer is using the incompatible deserializer FloatDeserializer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/0*n-ymPyoqaQzyYgiy.png" /></figure><h3>Poison pill in action</h3><p>If you want to see for yourself what a poison pill looks like, I have created an example project that uses an incompatible serializer and deserializer which mimics a poison pill. The kafka-poison-pill example project can be found on <a href="https://github.com/steptro/kafka-poison-pill">GitHub</a>. In case you don&#39;t have a local Kafka environment, the Confluent <a href="https://github.com/confluentinc/kafka-images/tree/master/examples">documentation</a> you can help you setting up Kafka locally. If you&#39;re already running Kafka, don&#39;t forget to update application.yml with your configuration if necessary. You can also read along to see what will happen. Consider this your spoiler alert warning!</p><p>After running the application, you can run the following command or pasting the url in your browser to trigger the poison pill:</p><pre>curl <a href="http://localhost:8080/produce-order">http://localhost:8080/produce-order</a></pre><p>In the logs you will now see a continuous stream of error logs. Here is an example of a log message:</p><pre>2021-06-13 13:21:27.196 ERROR 69190 --- [ntainer#0-0-C-1] essageListenerContainer$ListenerConsumer : Consumer exception</pre><pre>java.lang.IllegalStateException: This error handler cannot process &#39;SerializationException&#39;s directly; please consider configuring an &#39;ErrorHandlingDeserializer&#39; in the value and/or key deserializer<br>    at org.springframework.kafka.listener.SeekUtils.seekOrRecover(SeekUtils.java:194) ~[spring-kafka-2.7.1.jar:2.7.1]<br>    at org.springframework.kafka.listener.SeekToCurrentErrorHandler.handle(SeekToCurrentErrorHandler.java:112) ~[spring-kafka-2.7.1.jar:2.7.1]<br>    at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.handleConsumerException(KafkaMessageListenerContainer.java:1598) ~[spring-kafka-2.7.1.jar:2.7.1]<br>    at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.run(KafkaMessageListenerContainer.java:1210) ~[spring-kafka-2.7.1.jar:2.7.1]<br>    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) ~[na:na]<br>    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]<br>    at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]<br>Caused by: org.apache.kafka.common.errors.SerializationException: Error deserializing key/value for partition orders-0 at offset 32. If needed, please seek past the record to continue consumption.<br>Here is what happened:</pre><p>Here is what happened:</p><ol><li>The consumer tries to deserialize the record. Since the record is serialized using the StringSerializer and the consumer expects JSON, the consumer is not able to deserialize the series of bytes.</li><li>The consumer is not able to acknowledge the record, and thus the offset is not moving ahead.</li><li>Now the consumer will try to deserialize the record again which will fail again and thus the consumer will end up in an infinite loop. Each deserialization failure is logged and even after a few moments thousands of messages have already been logged.</li></ol><h3>Consequences</h3><p>You can imagine that if for every deserialization failure a message is logged, many gigabytes of logs are written to disk rapidly. Many production grade systems will also ship their logs to a centralized system where flooding this system can lead to huge costs. Also, finding other non-Kafka logs will become basically impossible. Depending on the size of the storage you have in place, all the storage could be filled by Kafka logs which will probably result in a non-functioning machine. So, in short, a poison pill could have quite a severe impact.</p><h3>How to deal with poison pills?</h3><p>There are four options of dealing with poison pills, however I would strongly recommend only one.</p><p>The first option is to wait until the retention period of the Kafka topic has passed, which is 7 days per default. After the retention period the poison pill is discarded. Waiting for 7 days until the consumer can consume messages again is far from ideal. There is the possibility to set the retention period to a lower number, which will discard poison pills earlier. However, records that are produced closely after the poison pill will likely be discarded as well. Depending on the situation this can be even more damaging.</p><p>The second option is to manually update the offset to after the offset of the poison pill. The advantage of this option is that you have a lot of control. You can set the offset to exactly to the offset after the poison pill. The disadvantage is that it is not straightforward. You must have access to the production Kafka cluster — which is never a good sign — and you will need to have knowledge about the Kafka binaries.</p><p>In case you do need to reset the offset programmatically you can use the following command:</p><pre>kafka-consumer-groups --bootstrap-server $BOOTSTRAP_SERVER --group $CONSUMER_GROUP --reset-offsets --to-offset $OFFSET --topic $TOPIC --execute</pre><p><strong>Note</strong>: The consumer should be stopped before resetting the offset</p><p>The third option is easier than the second option and does not require the execution of commands. It is also possible to change the consumer group and start consuming from the latest offset. The disadvantage of this ‘solution’ is that messages between the poison pill and the last produced record to the topic won’t be consumed and will be lost. Should another poison pill occur in the future, the consumer group will need to be changed again. The image below shows what happens after the consumer group is changed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*89EgJTXmWQtrQgzF.png" /></figure><p>The last and recommended option is to configure a ErrorHandlingDeserializer using Spring Kafka.</p><h3>ErrorHandlingDeserializer setup</h3><p>The first thing we have to do is to replace the deserializers by the ErrorHandlingDeserializer for both the key and value. Since the ErrorHandlingDeserializer will delegate the deserialization to the real deserializers, we need to add the classes where the ErrorHandlingDeserializer can delegate to. The delegate classes can be added to the config by adding the spring.deserializer.key.delegate.class and spring.deserializer.value.delegate.class properties:</p><p>application.yml</p><pre>spring:<br>  kafka:<br>    consumer:<br>      key-deserializer: org.springframework.kafka.support.serializer.ErrorHandlingDeserializer<br>      value-deserializer: org.springframework.kafka.support.serializer.ErrorHandlingDeserializer<br>    properties:<br>      spring.deserializer.key.delegate.class: org.apache.kafka.common.serialization.StringDeserializer<br>      spring.deserializer.value.delegate.class: org.springframework.kafka.support.serializer.JsonDeserializer</pre><p>How does the ErrorHandlingDeserializer work in practice? The ErrorHandlingDeserializer will try to deserialize the key and value using the delegated class. If no DeserializationException is thrown the record is passed to the consumer and will work as normal. However, if a DeserializationException is thrown, the record is no longer passed to the consumer. The configured ErrorHandler is instead called with the thrown exception and the failing record. After the ErrorHandler has handled the error, the consumer will resume consuming as if nothing has happened. The offset has now been moved forward. The ErrorHandler swallowed the poison pill and no more continuous streams of error messages.</p><p>Optionally, a simple bean can be configured that will log some additional information about the failing record compared to the default SeekToCurrentErrorHandler:</p><pre><a href="http://twitter.com/Bean">@Bean</a><br>public LoggingErrorHandler errorHandler() {<br>    return new LoggingErrorHandler();<br>}</pre><p>In case you have multiple consumers, it is also possible to programmatically configure the ErrorHandlingDeserializer. The following examples demonstrates how to configure a JsonDeserializer with the LoggingErrorHandler:</p><pre>private final KafkaProperties kafkaProperties;</pre><pre>private ConsumerFactory&lt;String, String&gt; jsonConsumerFactory() {<br>    JsonDeserializer jsonDeserializer = new JsonDeserializer();<br>    jsonDeserializer.addTrustedPackages(&quot;your.package&quot;);<br>    ErrorHandlingDeserializer errorHandlingDeserializer = new ErrorHandlingDeserializer(jsonDeserializer);</pre><pre>Map&lt;String, Object&gt; props = kafkaProperties.buildConsumerProperties();<br>    return new DefaultKafkaConsumerFactory&lt;&gt;(props, new StringDeserializer(), errorHandlingDeserializer);<br>}</pre><pre><a href="http://twitter.com/Bean">@Bean</a><br>public ConcurrentKafkaListenerContainerFactory&lt;String, String&gt; jsonListenerContainerFactory() {<br>    ConcurrentKafkaListenerContainerFactory&lt;String, String&gt; factory = new ConcurrentKafkaListenerContainerFactory&lt;&gt;();<br>    factory.setConsumerFactory(jsonConsumerFactory());<br>    factory.setErrorHandler(new LoggingErrorHandler());<br>    return factory;<br>}</pre><p>I have also created an example project, where the ErrorHandlingDeserializer is configured, which can be found on <a href="https://github.com/steptro/kafka-poison-pill/tree/master/kafka-poison-pill-error-handling">GitHub</a> as well. In this project you can again trigger the poison pill by running the following command or pasting the url in your browser:</p><pre>curl <a href="http://localhost:8080/produce-order">http://localhost:8080/produce-order</a></pre><p>With the ErrorHandlingDeserializer now configured you should see only one log message with the DeserializationException. Crisis averted 😃 !</p><h3>Dead letter topics</h3><p>You might have noticed that using the LoggingErrorHandler does not actually log the value of the poison pill, but instead only shows the sequence of bytes. It is possible to log the actual value of the poison pill, by publishing the poison pill to a so-called dead letter topic (DLT). You can think of a dead letter topic as a backup topic where records that were not able to be consumed are send to.</p><p>You can configure a DeadLetterPublishingRecoverer that will send the poison pill to the dead letter topic. It can be configured as follows:</p><pre><a href="http://twitter.com/Bean">@Bean</a><br>public SeekToCurrentErrorHandler errorHandler(DeadLetterPublishingRecoverer deadLetterPublishingRecoverer) {<br>    return new SeekToCurrentErrorHandler(deadLetterPublishingRecoverer);<br>}</pre><pre><a href="http://twitter.com/Bean">@Bean</a><br>public DeadLetterPublishingRecoverer publisher() {<br>    DefaultKafkaProducerFactory&lt;String, byte[]&gt; defaultKafkaProducerFactory = new DefaultKafkaProducerFactory&lt;&gt;(kafkaProperties.buildProducerProperties(), new StringSerializer(), new ByteArraySerializer());<br>    KafkaTemplate&lt;String, byte[]&gt; bytesKafkaTemplate = new KafkaTemplate&lt;&gt;(defaultKafkaProducerFactory);<br>    return new DeadLetterPublishingRecoverer(bytesKafkaTemplate);<br>}</pre><p>Since you’re most likely already configured a serializer and deserializer that is not using the byte[] type, we&#39;ll need to configure a separate serializer and deserializer for the DeadLetterPublishingRecoverer:</p><pre><a href="http://twitter.com/Bean">@Bean</a><br>public SeekToCurrentErrorHandler errorHandler(DeadLetterPublishingRecoverer deadLetterPublishingRecoverer) {<br>    return new SeekToCurrentErrorHandler(deadLetterPublishingRecoverer);<br>}</pre><pre><a href="http://twitter.com/Bean">@Bean</a><br>public DeadLetterPublishingRecoverer publisher() {<br>    DefaultKafkaProducerFactory&lt;String, byte[]&gt; defaultKafkaProducerFactory = new DefaultKafkaProducerFactory&lt;&gt;(kafkaProperties.buildProducerProperties(), new StringSerializer(), new ByteArraySerializer());<br>    KafkaTemplate&lt;String, byte[]&gt; bytesKafkaTemplate = new KafkaTemplate&lt;&gt;(defaultKafkaProducerFactory);<br>    return new DeadLetterPublishingRecoverer(bytesKafkaTemplate);<br>}</pre><pre>private ConsumerFactory&lt;String, byte[]&gt; bytesArrayConsumerFactory() {<br>    Map&lt;String, Object&gt; props = kafkaProperties.buildConsumerProperties();<br>    return new DefaultKafkaConsumerFactory&lt;&gt;(props, new StringDeserializer(), new ByteArrayDeserializer());<br>}</pre><pre><a href="http://twitter.com/Bean">@Bean</a><br>public ConcurrentKafkaListenerContainerFactory&lt;String, byte[]&gt; bytesArrayListenerContainerFactory() {<br>    ConcurrentKafkaListenerContainerFactory&lt;String, byte[]&gt; factory = new ConcurrentKafkaListenerContainerFactory&lt;&gt;();<br>    factory.setConsumerFactory(bytesArrayConsumerFactory());<br>    return factory;<br>}</pre><p>You can now create a separate consumer that is able to consume messages from the DLT topic:</p><pre><a href="http://twitter.com/Service">@Service</a><br>public class DltConsumer {</pre><pre><a href="http://twitter.com/KafkaListener">@KafkaListener</a>(topics = {&quot;orders.DLT&quot;}, containerFactory = &quot;bytesArrayListenerContainerFactory&quot;)<br>    public void recoverDLT(<a href="http://twitter.com/Payload">@Payload</a> ConsumerRecord&lt;String, byte[]&gt; consumerRecord) {<br>        log.info(&quot;Poison pill value: {}&quot;, new String(consumerRecord.value()));<br>    }<br>}</pre><p>In the <a href="https://github.com/steptro/kafka-poison-pill/tree/master/kafka-poison-pill-error-handling">example project</a> the DLT logic can be enabled by setting the property spring.kafka.dlt.enable to true. With the ErrorHandlingDeserializer and the DeadLetterPublishingRecoverer now configured you should see two log messages. One log message for the deserialization exception and one that displays the value of the poison pill.</p><p><strong>Note:</strong> In the consumer above the poison pill’s value is converted from bytes to a string. This conversion only works if the event value is a serialized string. In case the event value is of a different type, the poison pill consumer should convert it this type instead.</p><h3>In short</h3><p>A poison pill is a record that cannot be consumed, no matter how many times it is attempted by the consumer. Poison pills occur either because of a corrupt record , deserialization error or a schema mismatch. Without a configured ErrorHandlingDeserializer, many gigabytes of logs can be rapidly written to disk, which can cause the system to halt. The recommended way to handle a deserialization error is to configure an ErrorHandlingDeserializer, which will make sure that the consumer can continue processing new records. In case you need the actual value of a poison pill, a DeadLetterPublishingRecoverer can be configured, which allows you to log the actual value of the record.</p><p>I also provided an <a href="https://github.com/steptro/kafka-poison-pill">example project</a> in which you could see the effects of a poison pill and I showed how you can survive a poison pill. If you have any questions or improvements, feel free to start a new discussion on <a href="https://github.com/steptro/kafka-poison-pill/discussions">GitHub</a>.</p><p>Follow my blog for more upcoming posts about Kafka and related topics!</p><p><em>Originally published at </em><a href="https://stephantromer.dev/blog/how-to-handle-poison-pills-in-kafka"><em>https://stephantromer.dev</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a017d705a541" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Perfectionism in Programming]]></title>
            <link>https://medium.com/@stephantromer/perfectionism-in-programming-22e681d653e5?source=rss-f58432861889------2</link>
            <guid isPermaLink="false">https://medium.com/p/22e681d653e5</guid>
            <category><![CDATA[perfectionism]]></category>
            <dc:creator><![CDATA[Stephan Tromer]]></dc:creator>
            <pubDate>Fri, 16 Jul 2021 13:07:21 GMT</pubDate>
            <atom:updated>2021-07-16T13:07:21.129Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4i6mcJd4vAvuNERO.jpg" /></figure><p>First of all I would like to welcome you to my blog where I will be sharing my experiences in the software engineering world. Hopefully you will learn something new every time you read one of my blogs :).</p><p>A perfectionist is a person who refuses to accept any standard short of perfection. I consider myself a perfectionist and a competitive person. In this blog I will discuss my coding experience from a perfectionistic person’s view, the upsides and downsides of having a perfectionistic mindset and some tips for avoiding getting trapped in trying to reach this unattainable ideal.</p><p>I want to be the best at anything I decide to put effort in. I don’t settle for anything less than perfect or being the best. It can be requiring myself to be the best at my sport table tennis or winning a simple game of Monopoly. Sometimes winning a point is not even enough. I could have won the point earlier or maybe I was just lucky the opponent made a mistake. I tend to have a similar mindset for most things in life including programming. And let’s not forget about this blogpost. Needs to be great as well. I always try to get things right the first time. Needless to say, this blog has been a long time in the making.</p><p>For starters, being so demanding of yourself will make you have to deal with disappointments quite a lot. Especially in sports. Only one person can be the best. If I am not winning, I am losing. Being second or last is in that regard the exact same thing. It’s not first place.</p><pre>public class Calculator {</pre><pre>    private int x;<br>    private int y; </pre><pre>    // Method for adding two numbers<br>    public int add(int a , int b) { <br>        return a + b; </pre><pre>    } </pre><pre>    // method for subtracting two numbers <br>    public int  subtract(int a, int b){ <br>        return a - b; <br>    } </pre><pre>    public int Multiply() { <br>        return this.x * y; <br>    } <br>}</pre><p>I would see many imperfections in this code and would feel the urge to ‘fix’ all the code’s imperfections. I get the same urges when I encounter this code during my daily work. Inconsistent spaces, braces, new lines and capitalization, would be examples of the things I would fix. When I look at a piece of code or when I’m coding, I almost look at it as a painting. I would shuffle around code to make it symmetrical, balanced and simplistic, ensuring the code looks its best. The code should paint the perfect picture for when other people eventually read it. In my opinion the following code would look more elegant and readable:</p><pre>public class Calculator {</pre><pre>    private int x;<br>    private int y;</pre><pre>    // Method for adding two numbers<br>    public int add(int a, int b) { <br>        return a + b;<br>    }</pre><pre>    // Method for subtracting two numbers <br>    public int subtract(int a, int b){ <br>        return a - b; <br>    }</pre><pre>    public int multiply() { <br>        return this.x * this.y; <br>    } <br>}</pre><p>This is of course a small and isolated example since the code does the same thing and performs no different. Other people can also have a different perspective on how ‘perfect’ code looks like. Maybe some people didn’t even see a difference in the two pieces of code. This can be frustrating when you work in a project with many different programmers that all have their own coding style. Perfectionists could feel other programmers were lazy and didn’t do a good enough job. This obviously does not have to be the case.</p><p>It becomes most evident when reviewing PRs. I often feel that the naming of variables and methods and the layout of the code could be improved. Naming is of course very personal and is very much up to debate. However, I feel that code can be improved significantly by making the code look more ‘elegant’, which will make the code more readable. Readability is important because code is more often read than written. Adding whitespaces and blank lines to separate logical blocks of code will in my opinion improve the code and will make it easier to understand for the reviewer and the programmers that will inevitably read the code later.</p><h3>Advantages</h3><p>Being a perfectionist comes as mentioned with both its advantages and disadvantages. Advantages include not being easily satisfied with a solution, high level of ambition, increased motivation, perseverance, attention to detail and striving to be the best version of yourself.</p><p>Perfectionists often will be quite ambitious in life. They will set goals for themselves and do everything they can to reach those goals. Often sacrificing other things to make sure they will not fail. They do this to get an edge over the competition who are not willing to work as hard. An example of this could be spending a couple of hours outside work hours to apply the finishing touches to a solution.</p><p>Setbacks are also not likely to impact perfectionists. They will still put in the effort and persevere through difficulties they encounter</p><p>Attention to details is something perfectionists pride themselves in. Finding little mistakes is a strength and raises the quality of work of their teammates as well as their own. This translates to programming in writing high-quality code. Not just writing code that works, but code that is maintainable and follows best practices.</p><h3>Disadvantages</h3><p>All these advantages come at a cost. One of the -obvious- disadvantages is that developing solutions takes more time. By continuously perfecting the solution, the solution will never be done. There is always be something to improve. There comes a point where the programmer should move on to the next feature. This point will come later in time for a perfectionist</p><p>Another disadvantage is that perfectionism can also have a quite severe effect on your mood or state of mind. Since you never have the feeling that a task or solution is done, you will not often have the satisfactory feeling of completion. You will be worrying about small mistakes and put yourself under unnecessary pressure.</p><h3>Tips</h3><p>To manage having a perfectionistic mindset and feel the urge to refactor ten different services, I like to consider the following:</p><ul><li>Will these changes make any significant difference in the performance of the code? Is it worth my time? This can be a question for the long-term or the short-term. If there isn’t a clear answer, I set a deadline for myself and if I feel I won’t make this deadline anymore, I will move on.</li><li>I often like to ask a coworker/teammate what he or she thinks of the current solution and whether it needs to be improved or is sufficient as is. Pair programming is often a good way to lessen the perfectionistic effects, due to the instantaneous feedback on the written code.</li><li>Try to be satisfied with a good working solution instead of a perfect solution. Which is always easier said than done 😊.</li></ul><p>In the end I would say you are a good programmer if you are able to choose the right moments to be perfectionistic. You can call them selective perfectionists. They have a good understanding in which code needs to be absolutely spot-on and which code isn’t that important.</p><p>Over time I learned being a perfectionist doesn’t mean it has to be perfect. You can still strive to be perfect, but if circumstances do not allow it to be perfect, it does not mean it is not a good solution.</p><p>In my next blog I will be talking about how to handle poison pills in Apache Kafka. Until then.</p><p><em>Originally published at </em><a href="https://stephantromer.dev/blog/perfectionism-in-programming"><em>https://stephantromer.dev</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22e681d653e5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>