<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Poovamraj T T</title>
    <description>The latest articles on DEV Community by Poovamraj T T (@poovamraj).</description>
    <link>https://dev.to/poovamraj</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F156336%2Fcd5f76a3-0bd9-4736-bd70-d786665690bb.png</url>
      <title>DEV Community: Poovamraj T T</title>
      <link>https://dev.to/poovamraj</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/poovamraj"/>
    <language>en</language>
    <item>
      <title>Make Spring Boot Lean And Mean - Throwing Away Hibernate and Java from Spring Boot</title>
      <dc:creator>Poovamraj T T</dc:creator>
      <pubDate>Mon, 17 May 2021 19:38:53 +0000</pubDate>
      <link>https://dev.to/poovamraj/make-spring-boot-lean-and-mean-throwing-away-hibernate-and-java-from-spring-boot-e77</link>
      <guid>https://dev.to/poovamraj/make-spring-boot-lean-and-mean-throwing-away-hibernate-and-java-from-spring-boot-e77</guid>
      <description>&lt;p&gt;Developing a backend application requires huge stability and data modeling is one of the pieces of software that is toughest to migrate hence choosing a reliable and stable technology is a necessity.&lt;/p&gt;

&lt;p&gt;Spring Boot is one of the most reliable frameworks in the Java ecosystem. There are great efforts in developing leaner and better frameworks but Spring Boot seems to have great examples and solutions to many common problems faced in backend development. But it is hard to overlook the aged development methodology and impact on productivity.&lt;/p&gt;

&lt;p&gt;I recently started writing an application and I have overhauled my Spring Boot boilerplate to ensure the latest development productivity improvements can be ensured where ever possible&lt;/p&gt;

&lt;h1&gt;
  
  
  Data Layer Improvements - Irritating parts of Hibernate
&lt;/h1&gt;

&lt;p&gt;1) I realized OneToOne mapping can have multiple entities on the child table unless we mark it with &lt;code&gt;unique=true&lt;/code&gt;. This is one such example where we have to understand the nook and cranny of Hibernate just to avoid severe issues.&lt;/p&gt;

&lt;p&gt;2) Bidirectional mapping to join from child to parent&lt;/p&gt;

&lt;p&gt;3) Writing complex queries are sometimes impossible due to the domain structure we design&lt;/p&gt;

&lt;p&gt;4) Defining your SQL tables with Java POJOs might feel all good initially until the reality of complex DB migrations comes into the workflow.&lt;/p&gt;

&lt;p&gt;Initially, to overcome writing the complex queries issues which were impossible with Hibernate, I started looking for replacements that were strongly typed. I stumbled upon jOOQ which I fell in love with instantly. But to be on the cautious side I integrated it and used it just for complex queries. After all, jOOQ itself mentions Hibernate is good for CREATE, UPDATE, and DELETE operations.&lt;/p&gt;

&lt;p&gt;jOOQ has the coolest features that no other ORM I have seen has. It generates the Object representation of your Tables using a code-gen module. &lt;/p&gt;

&lt;p&gt;This can be done by connecting it to a Database but I felt this was an unwanted dependency at build/dev time.&lt;/p&gt;

&lt;p&gt;I overcame this by integrating Liquibase using which jOOQ can generate the Object representation. Initially, this felt like overkill but understanding the uses of DB Migration libraries like Flyway/Liquibase made me realize how important such a tool is for DB migration.&lt;/p&gt;

&lt;p&gt;Now that I had my DB definitions in Liquibase and Object definitions generated by jOOQ it felt obsolete to use Hibernate which I was only using for CREATE, UPDATE, DELETE operations and it started to feel more and more obsolete.&lt;/p&gt;

&lt;p&gt;Finally, I took the big leap of removing the spring-data-jpa dependency as a whole.&lt;/p&gt;

&lt;h1&gt;
  
  
  Improving Service Layer
&lt;/h1&gt;

&lt;p&gt;Many shy away from Spring Boot because of it being a Java framework. After all, just after hearing the word Java, It is impossible for a developer to not be scared of some pattern like &lt;code&gt;AbstractFactoryBuilderAdapter&lt;/code&gt;. But what we have to understand is that it is a JVM-based framework and languages like Scala and Kotlin integrate nicely with Spring Boot. Moving my application from Java to Kotlin felt like a breath of fresh air since I got all the following features along with it&lt;/p&gt;

&lt;p&gt;1) Nullability checks&lt;br&gt;
2) Type inference&lt;br&gt;
3) Data classes&lt;br&gt;
4) Concise code&lt;/p&gt;

&lt;p&gt;The above efforts made my personal boilerplate feel very similar to Nodejs/Typescript/TypeORM combo that I use at my work.&lt;/p&gt;

&lt;p&gt;Java/JVM is a great piece of software overlooked by many developers for shiny new frameworks. I have seen many startups and recently even a unicorn moving from languages like Go to Java due to many reasons. Some of the most complex features required for enterprise development are built into Java-based frameworks like Spring (For example - I was not able to find Access Control List feature in any other framework but in &lt;a href="https://docs.spring.io/spring-security/site/docs/3.0.x/reference/domain-acls.html"&gt;Spring&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;I would like to hear your comments on this. You can follow me at Twitter - &lt;a href="https://twitter.com/poovamraj"&gt;https://twitter.com/poovamraj&lt;/a&gt;&lt;/p&gt;

</description>
      <category>spring</category>
      <category>hibernate</category>
      <category>java</category>
      <category>backend</category>
    </item>
    <item>
      <title>How to think in Next.js - Learn the Mental Model</title>
      <dc:creator>Poovamraj T T</dc:creator>
      <pubDate>Sat, 08 May 2021 19:10:48 +0000</pubDate>
      <link>https://dev.to/poovamraj/how-to-think-in-next-js-learn-the-mental-model-15gg</link>
      <guid>https://dev.to/poovamraj/how-to-think-in-next-js-learn-the-mental-model-15gg</guid>
      <description>&lt;p&gt;The most important thing when learning a new framework, especially ones which have a new way of doing things is to understand how to think (or design) solutions to a problem. &lt;/p&gt;

&lt;p&gt;Next.js claims the major issue it fixes on top of React.js is "Pre Rendering"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Pre Rendering&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Historically frameworks like JSP used to render the HTML content of the page on the server-side and send the rendered HTML page to the browser. This is in contrast to the approach used in modern frameworks like React.js where the web page first loads the JS and then it renders all the required HTML elements on the client (read it as the browser) side&lt;/p&gt;

&lt;p&gt;The concept of Client-side rendering works well as it completely separates the backend and frontend. But there are certain issues that can arise from client-side rendering.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Search Engines tend to parse the HTML file and index it. This scraping process is not optimized for sites that do client-side rendering.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When you are rendering on the client end, whenever an API call is made, the request has to travel all the way from the client who can be in the US to the server which can reside in JAPAN. This can severely slow down the performance. Instead, if we are rendering on the server end, most of the data can be fetched easily as the rendering can happen at the same place as the server.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you do not have the above 2 use-cases, you can simply use the traditional client-side rendering application. At least, that's what I am doing.&lt;/p&gt;

&lt;p&gt;This concept is generally called &lt;strong&gt;Server-Side Rendering (SSR)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;But Next.js tends to use the word "Pre Rendering". This is to distinguish the two major use cases the framework is used for&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Static Rendering&lt;/li&gt;
&lt;li&gt;Server-Side Rendering&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Static Rendering&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When the HTML code is generated as soon as we run the build, This is called static rendering.&lt;/p&gt;

&lt;p&gt;Static rendering is useful for Homepages or Blogs where the content of the page doesn't change often (For example - each reload won't have different data like a stock market site).&lt;/p&gt;

&lt;p&gt;We can write a "Page" by exporting a JSX component under the pages folder.&lt;/p&gt;

&lt;p&gt;For example - writing a js file named 'hello.js' that exports a JSX component under the pages folder will give us a &lt;/p&gt;

&lt;p&gt;&lt;code&gt;localhost:3000/hello&lt;/code&gt; page &lt;/p&gt;

&lt;p&gt;Creating a new folder will add it as a path.&lt;/p&gt;

&lt;p&gt;For example - creating a folder named 'blog' under pages folder with a js file named hello that returns a JSX component provides us with&lt;/p&gt;

&lt;p&gt;&lt;code&gt;localhost:3000/blog/hello&lt;/code&gt; page&lt;/p&gt;

&lt;p&gt;It is as simple as writing an HTML file under a webserver and accessing it using its path.&lt;/p&gt;

&lt;p&gt;Next.js also provides a feature where the static pages can be rendered dynamically. Let me explain a use case&lt;/p&gt;

&lt;p&gt;Let's say you write blogs that are maintained in a Database (actually they are usually maintained in a component called Headless CMS, but for simplicity, let's say a database)&lt;/p&gt;

&lt;p&gt;If you want to fetch the content from that database instead of writing the content of the blog directly on the JS file. You can use the method &lt;code&gt;getStaticProps&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will fetch us the content of the blog "WHILE BUILDING THE PROJECT" and pre-render the HTML pages for us&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Server-Side Rendering&lt;/strong&gt;&lt;br&gt;
The HTML code is generated only when the request hits our server for Server-Side Rendering. &lt;/p&gt;

&lt;p&gt;This is useful for use cases like Forum or Saas applications That has the potential to change for each request.&lt;/p&gt;

&lt;p&gt;The pages (or routing) concept is similar to static rendering. Any js file returning a JSX component inside the pages folder is a separate page (or route)&lt;/p&gt;

&lt;p&gt;Each time this route is called on the browser, the Next.js framework tends to render the page and provide a full HTML page as a response.&lt;/p&gt;

&lt;p&gt;Any data that needs to be fetched from the backend for rendering this page can be returned using getServerSideProps.&lt;/p&gt;

&lt;p&gt;For example - A table with all the stock prices can be rendered each time when a request is made. The required data to fill the stock price can be fetched inside getServerSideProps. Since the rendering can happen at the same location as the backend, the round trip time to make this request will be very very less.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dynamic Routing&lt;/strong&gt;&lt;br&gt;
There can be a use case where all the routes will not be known to us. For example - In the previous blog example I mentioned where the content can be fetched from the DB, Imagine what will happen when a new blog is added to the DB.&lt;/p&gt;

&lt;p&gt;We cannot be writing a new page each time a new blog is written right? (i.e) The routes that can be reached can change dynamically based on a different source of data rather than the JS files we created.&lt;/p&gt;

&lt;p&gt;For this, we have the concept of Dynamic Rendering. Any file under the pages folder with the name wrapped with brackets like [].js can have a method called &lt;code&gt;getStaticPaths&lt;/code&gt; which can be used to return all the possible paths. These paths can also be rendered for each request using an option called &lt;code&gt;blocking&lt;/code&gt; which needs to be set in the return value.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Understanding the mental model of a framework easily helps us solve problems using that framework. While first learning React we all would have faced the issue of understanding the uses of a "state" and a "prop" while now it can be written without a second thought. In a similar way, to learn Next.js, the first thing to learn would be the uses of &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;getStaticProps&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;getServerSideProps&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;getStaticPaths&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Next.js provides a lot more great features like &lt;code&gt;&amp;lt;Link/&amp;gt;&lt;/code&gt; &lt;code&gt;&amp;lt;Image/&amp;gt;&lt;/code&gt; &lt;code&gt;&amp;lt;Head/&amp;gt;&lt;/code&gt;. But once the above differences and uses are understood, the rest should be a walk in the park!&lt;/p&gt;

&lt;p&gt;I would love to discuss this topic and learn more if you have something to share! &lt;/p&gt;

&lt;p&gt;You can find me on Twitter at - &lt;a href="https://twitter.com/poovamraj"&gt;https://twitter.com/poovamraj&lt;/a&gt;&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>react</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
