<?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 Beniasaad Achraf on Medium]]></title>
        <description><![CDATA[Stories by Beniasaad Achraf on Medium]]></description>
        <link>https://medium.com/@acbeni?source=rss-31cb40d17995------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*CfMUdFOEiO4HAXFDcDIDeQ.png</url>
            <title>Stories by Beniasaad Achraf on Medium</title>
            <link>https://medium.com/@acbeni?source=rss-31cb40d17995------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 19:14:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@acbeni/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[Ep2: I want to become a developer, but don’t know where to start]]></title>
            <link>https://medium.com/@acbeni/ep2-i-want-to-become-a-developer-but-dont-know-where-to-start-ba7e16145df1?source=rss-31cb40d17995------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba7e16145df1</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Beniasaad Achraf]]></dc:creator>
            <pubDate>Wed, 04 Dec 2019 02:16:28 GMT</pubDate>
            <atom:updated>2019-12-04T02:16:28.475Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*c7Q-yjAwljdYWlj5" /></figure><p><a href="https://www.edutopia.org/literacy-computer-programming">Programming is the new literacy</a>, whether you like it or not, you won’t be able to understand most of what’s happening in the world unless you got a glimpse about programming. Some of the most revenue-generating companies nowadays are IT companies, all your data is stored in some hard drive somewhere, there is a lot of ethical discussion about the rise of new IT empires, and electronic warfare is the new battlefront, These issues aren’t only geek discussions but issues that have repercussions on the real world like the <a href="https://www.wired.com/amp-stories/cambridge-analytica-explainer/">Facebook Cambridge Analytica scandal…</a></p><p>With all this, people feel the need to understand a bit of what is IT about. And some of them try to get there hand dirty. There are also new graduates who try to make sense of the little of everything they learned at universities and try to build something useful with it. All these people come to the inevitable question, where should I start?</p><p>Books are your best friend, there is no denying it, the question is rather which book. here is the main problem with programming, which is a bit unique, the resources aren’t scarce but rather too abundant, actually so abundant that you can’t decide where to start from, and sometimes where to stop.</p><p>I myself have lived this confusion in the past, and the question never gets outdated, people always ask where do I have to start to become a programmer, and what shortcuts should I take. While I don’t believe in shortcuts since only through hard work anything useful can be achieved, I can, however, provide a map (based on my humble experience), that would help you at least see your destination and then it’s up to you to take the journey.</p><h3><strong>Eagle eye view</strong></h3><p>Let&#39;s start with a simple application, this application, allows you to send messages, and lets model it as abstract as possible</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/281/1*2QNk_EPqm9rgJdbqLFDZ9Q.png" /></figure><p>The concept here is so easy, you enter the text, it gets to your application, through all the abstraction layers (physical components, operating system…), then displays some output on the screen.</p><p>Already here you see a very important aspect of applications, it’s composed of components communicating with each other, these components can be abstracted away as classes, functions, files…, but nonetheless they are just nodes in a diagram.</p><p>Now if we try to make the application, more useful (by actually sending the message!), we just add more nodes to the diagram, maybe with the simple difference that the connections are much less reliable, I mean, after all, It’s more common that one can’t send a message because of network coverage than it is because of losing connection between the keyboard and the messaging app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*3AHbxqlJvfFjP11L32cytw.png" /></figure><p>The point I’m trying to say here is that the most simple and most complex applications are all about building nodes, and connecting them in a diagram, in other words, your application from inside and outside looks like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OHzrbBVFyetgLtt6.jpg" /></figure><p>So in order to build these structures, you need a language to program your nodes and protocols to connect them, let&#39;s dive a bit of how you can acquire knowledge in these blocks.</p><h3>1- choosing a language</h3><p>In our simple example, the nodes, are the smart part, they execute some logic, in order to translate your logic to a less abstract form that the machine can understand you need a programming language.</p><p>Now the choice of the programming language is always a hot topic, there is always the tribe that claims that they were blessed with the most expressive language. There are almost 400 languages in use nowadays, and getting to use languages that are ranked more than 20, is as rare as getting to google’s second search page. you don’t get there unless your truly desperate. but what about the first 20.</p><p>In my humble experience, in most cases, I use the language which is the industry convention for that task (due to technical, historical… reasons). If I want to develop frontend I use javascript, for enterprise app: java, android app: Kotlin… it&#39;s just simple, you would probably find someone that already tried to do the same task, and probably most useful libraries are written in that conventional language. but if you are already versed in the pros and cons of multiple languages then you might be able to judge if it’s worth it to go against the current.</p><p>Now here is a tip while documenting yourself about a language at the beginning, focus at what the industry chose this language for, and drop everything else. For example, as I said earlier, in the world of enterprise applications, java is a king, so when you find an article about building UI with java, ask yourself is the UI a core part of an enterprise App? NO, so skip all those Swing, Awt, … tutorials. The winner in the UI world has already been chosen and most attempt to go against it (especially by a beginner), is mere suffering for the most cases. To be fair, one of the most awesome IDEs, Intellij, has opted for use of java in a UI, which contradicts my point, and this is why I stress that I m providing heuristics to skip the useless parts in the huge amount of doc, but if you know what your doing, then you can go against whats common (and probably stop reading this article 😄)</p><p>for a more elaborate discussion about language choice, I would recommend the following article.</p><p><a href="https://mkdev.me/en/posts/how-to-choose-a-programming-language">How to choose a programming language? | articles about programming on mkdev</a></p><h3>2- Design patterns</h3><p>So now you know the alphabet of a language, which means you have a tool, but not necessarily know how to use it. each language promotes a certain paradigm. Java, for example, encourages object-oriented programming, Haskel encourages pure functional style, … . Each language has syntactic features that allow it to fulfill its own promises, but even these syntactic features are far from getting you near that goal if you don’t know what you are doing, or which patterns to follow. you can write procedural code in java, and even object-oriented structures using the shell scripts (yep that’s a thing).</p><p>This leads us to the second part, <strong><em>language paradigms and design patterns</em></strong>. Before coding in a language read about what paradigm it promotes. What are the common conventions in package/namespace structures/naming, and what the most recommended design patterns while working with that language. on the one hand, this enhances your productivity by using the language&#39;s features and libraries to your advantage, on the other hand, your partners would able to navigate through what you wrote and be able to focus more on your business logic.</p><h3>3- Algorithmics</h3><p>Once you build a system you should be able to judge the amount of work that is done by it and whether the time it takes it to achieve that task is acceptable, this leads us to the second point, algorithmics. First of all, this would allow you to know common solutions to common problems, like sorting elements, finding shortest path…, and second this would give you a metric of the complexity of your system, and the capacity to judge whether your code can get a solution in a reasonable time or whether you should opt for a less complex solution.</p><p>For this, there are multiple online judges, that have problem sets, and that can evaluate both the correctness and processing time for your solution. even big companies use these judges to be able to preselect their candidates since for them algorithmics are alphabets of their tasks especially the top innovators.</p><h3>4- Communication protocols</h3><p>At this point you already can write applications, now these applications, have internal communication protocols, that are abstracted away, for example, if you want to display data on your terminal you just push your data to a console object. these abstractions were successful due to the replayability/low latency of internal communications. Now passing by the external network is another story, errors there are more common, and until now most attempts to abstract the network were failures. This means that you have to learn about a communication protocol, to be able to build something useful,</p><p>Which protocol should you chose, totally depend on the Domaine you opted for, there are protocols for messages, video streaming, embedded devices…</p><p>Each protocol focuses on a special aspect, reliability, speed, power consumption…, for a starter you shouldn’t get through all this mess but focus at least at one protocol, for the current times, I would recommend HTTP, since it’s one of the most used applicative protocols, and once you understand the basic principles you can switch to other protocols that are more adapted to your use case.</p><h3>5- Use the benefits of the marvelous internet</h3><p>You re lucky to be living today, there are plenty of free online IDEs, rest mocking tools…, so you can have a workspace online, develop your programs, have interactive exercises and even deploy an app in a matter of clicks, use that to your benefit since this hides some complexity of deployment process, that you re better off when you start coding and trying still to figure out why your hello world code doesn&#39;t work.</p><p>Now, this is still a very simplistic view about programming, it rather tries to help you make your first steps. The backend, frontend, databases, … are their own battlefields with their warriors, ninjas, and musketeers, you need the patience to be able to fight among these armies, but the journey is worth it, and no matter how hard the path seems, keep focus on the light at the end of the tunnel, and hope you all the good luck 🤗</p><p>here is the link to EP1 <a href="https://medium.com/@acbeni/technotes-ep1-add-graphql-support-in-your-ide-74e2e4f425cd">https://medium.com/@acbeni/technotes-ep1-add-graphql-support-in-your-ide-74e2e4f425cd</a></p><p><em>Like what you read? follow me here, on </em><a href="https://twitter.com/BENIASAADAchraf"><em>Twitter</em></a><em> ,</em><a href="https://www.linkedin.com/in/achraf-beniasaad-915bb44b/"><em>LinkedIn</em></a><em> and</em></p><p><em>Blog </em><a href="https://brainya.com/"><em>https://brainya.com/</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba7e16145df1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TechNotes Ep1: add GraphQL support in your IDE]]></title>
            <link>https://medium.com/@acbeni/technotes-ep1-add-graphql-support-in-your-ide-74e2e4f425cd?source=rss-31cb40d17995------2</link>
            <guid isPermaLink="false">https://medium.com/p/74e2e4f425cd</guid>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Beniasaad Achraf]]></dc:creator>
            <pubDate>Wed, 27 Nov 2019 21:54:06 GMT</pubDate>
            <atom:updated>2023-10-25T21:38:33.812Z</atom:updated>
            <content:encoded><![CDATA[<h3>Ep1: add GraphQL support in your IDE</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*UPFC_52eDYn5UIJWz7ZEJA.png" /></figure><p>Today I am going to talk about how to make your IDE able to analyze the structure of your GraphQL queries, but before I start, since this is Episode 1 of my series. Let me explain what I am trying to achieve here 😄</p><p>Like every developer, finding solutions for dev issues is part of my daily life, while my findings in the process are helpful for someone else walking the same path, they aren’t good enough to write a full-fledged article, because at the end they are just tips…</p><p>This is why I started this series, to share these little findings and get something back to the dev community.</p><p>So let start 👷</p><h3>The problem</h3><p>While trying to use the GraphQL endpoint, for instance, the <a href="https://medium.com/u/26cde32e6189">commercetools</a> <a href="https://docs.commercetools.com/graphql-api">GraphQL</a> endpoint I had to use the <a href="https://github.com/graphql/graphiql">Graphiql</a> to check the correctness of my queries, which was a nice tool, I still had to get back and forth to my editor, which might become a bit annoying and I was wondering is it possible to make my ide check my queries syntax directly 🤔, unsurprisingly the answer is yes and here are the steps I followed to get there</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/1*9BWaSybwOVDkQT2M0KjEEg.gif" /><figcaption>Graphiql editor</figcaption></figure><h4>Step 1: Getting the schema</h4><p>Since the GraphQL supports introspection, there was a lot of tools that allow schema fetching, for instance, <a href="https://www.npmjs.com/package/get-graphql-schema">https://www.npmjs.com/package/get-graphql-schema</a>. of course in my use case, I had to add oAuth headers, since the API endpoint itself was secured.</p><p>Still, by curiosity, I was wondering how can I use, the <a href="https://graphql.org/graphql-js/utilities/">GraphQL utilities</a>, to get the schema, I was surprised how good the tooling was, and how easy it was to build a schema fetcher</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/69d5e0059b96e3ea088002652686d827/href">https://medium.com/media/69d5e0059b96e3ea088002652686d827/href</a></iframe><p>this code relies on <a href="https://medium.com/u/26cde32e6189">commercetools</a> typescript SDK <a href="https://www.npmjs.com/package/@commercetools/typescript-sdk">https://www.npmjs.com/package/@commercetools/typescript-sdk</a> to make the requests, you can find more example <a href="https://commercetools.github.io/nodejs/sdk/api/typescriptSdk.html">the docs</a>.</p><p>Simply it followed the steps: <em>execute introspection =&gt; build schema =&gt; print schema </em>(<a href="https://github.com/acbeni/medium-technotes/blob/master/ep1/src/helper.ts">the code can be found here </a>)</p><p>the resulting schema was the following <a href="https://github.com/acbeni/medium-technotes/blob/master/ep1/ctp.graphql">https://github.com/acbeni/medium-technotes/blob/master/ep1/ctp.graphql</a></p><h4>Step 2: Adding IDE support</h4><p>I used this plugin <a href="https://github.com/Quramy/ts-graphql-plugin">https://github.com/Quramy/ts-graphql-plugin</a>, to make the IDE aware of my GraphQL schema definition.</p><p>basically, as the readme mentions add the plugin via</p><pre> yarn add -D ts-graphql-plugin</pre><p>and then use this plugin in your tsconfig file as follows.</p><pre>&quot;plugins&quot;: [      <br>     {        <br>        &quot;name&quot;: &quot;ts-graphql-plugin&quot;,        <br>        &quot;schema&quot;: &quot;ctp.graphql&quot;,             <br>        &quot;tag&quot;: &quot;print&quot;      <br>     }<br>]</pre><p>you can see the full tsconfig here <a href="https://github.com/acbeni/medium-technotes/blob/master/ep1/tsconfig.json">https://github.com/acbeni/medium-technotes/blob/master/ep1/tsconfig.json</a></p><p>as you see you have to specify the path to the schema previously fetched <em>ctp.graphql</em></p><p>and the function that would receive the GraphQL query.</p><p>once done restart the ide, and now you ll have the support of the IDE in your GraphQL queries:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/476/1*JxnKkItKBnQiVwYQ6IG0MA.gif" /></figure><p>That&#39;s it now the IDE helps you navigate the data of your GraphQL endpoint.</p><p><strong>Takeaways</strong></p><ul><li>While exploring how actually this plugin does this magic, I was led to discover typescript plugins at <a href="https://github.com/microsoft/TypeScript/wiki/Writing-a-Language-Service-Plugin">https://github.com/microsoft/TypeScript/wiki/Writing-a-Language-Service-Plugin</a> , as mentioned in this page these plugins don’t alter the language features but only the editing experience, and it was really good to see how far the usage of the<a href="https://en.wikipedia.org/wiki/Language_Server_Protocol"> language server protocol</a> can enhance the user experience.</li><li>You can specify tagged template strings (which in our case was the <em>print</em> function)</li></ul><pre>print`</pre><pre>  query{</pre><pre>      carts{</pre><pre>         count</pre><pre>     }</pre><pre>   }</pre><pre>`</pre><p>these tags allow you to parse template literals with a function, if curious you’ll find more detail <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals</a></p><p>That’s it folks 🎉 hope this article might be of help to you 🙋‍♂</p><p>The code for this article can be found here <a href="https://github.com/acbeni/medium-technotes/tree/master/ep1">https://github.com/acbeni/medium-technotes/tree/master/ep1</a></p><p><em>Like what you read? follow me here, on </em><a href="https://www.linkedin.com/in/achraf-beniasaad-915bb44b/"><em>LinkedIn</em></a><em> and</em></p><p><em>Blog </em><a href="https://brainya.com/"><em>https://brainya.com/</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=74e2e4f425cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writing Your First Code Generator]]></title>
            <link>https://medium.com/commercetools-tech/ideas-on-writing-a-code-generator-b7f474e13427?source=rss-31cb40d17995------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7f474e13427</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[gradle]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Beniasaad Achraf]]></dc:creator>
            <pubDate>Fri, 25 Oct 2019 10:00:57 GMT</pubDate>
            <atom:updated>2023-10-25T21:37:54.864Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tDuo9dpFW8wqVGhfp9cv-g.jpeg" /></figure><p>While in most industries, there is fear of automation and the impact it might have on the job markets, software engineering is the total opposite. The whole purpose of software engineering is to automate tasks that can be done by the machine, then come the question, isn’t writing code just another task that can be automated?</p><p>In general, no. If your code executes some kind of complex logic it’s already difficult to write, maintain and make sure it does what it is supposed to do. However, most of our code is just simple and void of logic. We spend a lot of time writing entities and config classes whose sole purpose is to carry data. Since they don’t have logic they can be generated, the only constraint is that their structure should be documented somehow somewhere.</p><p>While the concept of code generation itself is widely spread among developers, I still think that people underestimate the power of it, or overestimate the effort involved in writing code generators. So I’m gonna take a specific case where information about the code you want to write already exists in a structured format (easy to parse), such as JSON, Yaml, CSV… In this case, I’ll build the following very simple chain to generate the code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*56P0eg0hmZA3_7zOdjGKOQ.png" /><figcaption>Code generator chain</figcaption></figure><h3>1. Defining the boring task</h3><p>Let’s take a developer for example, “Dave”, in some project he has a couple of properties, that are already defined in some property file, such as the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9bc8961d31587b35e0ec3a2d07d0d46b/href">https://medium.com/media/9bc8961d31587b35e0ec3a2d07d0d46b/href</a></iframe><p>To access these properties from a java project, he uses something like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f021cfc67eb61e88943397706b770ccd/href">https://medium.com/media/f021cfc67eb61e88943397706b770ccd/href</a></iframe><p>This code wasn’t safe enough by Daves standards, since with each refactoring some property may change the name, and some code trying to retrieve it somewhere might fail silently. 😢</p><p>To fix that Dave wanted to opt for a simple solution, which is writing a java file that we update each time we update the properties file. It would be something as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b0571a38ab34e7539aa0429400fb694/href">https://medium.com/media/3b0571a38ab34e7539aa0429400fb694/href</a></iframe><p>This way any change in naming would result in a code that doesn’t compile anymore. Pretty good, huh! Except that there are dozens of these properties files throughout the app, and some are huge. So he starts thinking; wouldn’t it be better to just write a piece of code that does that for him?</p><h3>2. Checking the requirements</h3><ul><li>Does the code have a structured format(can be parsed)? =&gt; YES (<a href="https://en.wikipedia.org/wiki/.properties">Properties file</a> have a structure that makes it easy to associate keys with values )</li><li>Is it possible to write a parser for this format? =&gt; YES (in this lucky case the parser is included in the JVM)</li></ul><p>That means that in this easy case (for demo purpose), we already have the first two blocks of our chain. In other cases, it might be that you have to build a parser which is not always an easy task. If you use popular formats (JSON, Yaml… ) to store your data however, you can find open-source parsers. All you have to do is to implement the tree traversal logic.</p><p>So at this point you have the data already parsed, now we should evaluate what templating engine we should use to put our data in the file format (Java class for this example).</p><h3>3. Evaluating templating engines</h3><p>There are plenty of templating engines, such as <a href="https://handlebarsjs.com/">Handlebars</a>, <a href="https://mustache.github.io/">Mustache</a>, etc… They do a wonderful job but still have plenty of weaknesses. Most of them lack IDE support, they also contain placeholders that expect some model (Beans in the case of java for example) which is tightly coupled to the template and soon become difficult to change on demand. One other issue that arises is that some of them support some <a href="https://en.wikipedia.org/wiki/Domain-specific_language">DSLs</a> to write simple functions (for example to format strings…), which are separate languages, and the IDE can’t do much to help you there either 🤷‍♂ These reasons were enough for me to avoid these templating engines at all costs.</p><p>If you want to write code in a single language like java or Kotlin, there are projects such as <a href="https://github.com/square/javapoet">javapoet</a> and <a href="https://github.com/square/kotlinpoet">kotlinpoet</a>, that make writing code generators easy and safe. The only thing I have against these tools is that they are too verbose, it takes a lot of code to generate simple code blocks, also it isn’t guaranteed that you’ll find a file generating libraries for every language. I used some of these in the past, but while working in a polyglot environment where we had to generate code for java, typescript, etc., these tools were limited to only some of the languages we wanted to generate.</p><p>The solution I like most for templating is using Kotlin multiline string for templates. I like it because it’s simple yet powerful because Kotlin strings allow Kotlin expressions inside which gives you access to all the language features Kotlin offers inside your template. Still, even Kotlin wasn’t perfect for code generation and here is why. let’s take a look at the following Kotlin code</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd454556024fc441e8eb8645e7cfb758/href">https://medium.com/media/cd454556024fc441e8eb8645e7cfb758/href</a></iframe><p>The code above generates the following config class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a214b5df04539b39ea4d063ef8ca1842/href">https://medium.com/media/a214b5df04539b39ea4d063ef8ca1842/href</a></iframe><p>In case your OCD didn’t help see what’s wrong, the indentation isn’t added correctly, this might work just fine in case of java, but in languages such as Python, this is unacceptable since indentation itself has a semantic. So how can we fix that?</p><p>To fix the indentation issue, I wrote a <a href="https://github.com/brainya/typesafe-config/blob/afde37dc54f7c2e38ce58a80a78d6e53d99b6a40/typesafe-config-core/src/main/kotlin/com/brainya/typesafe/core/utils/RenderingUtils.kt#L192">small utility function that</a> will help us keep the indentation, just surround your block with &lt; &gt; characters, and your code will be indented correctly. Here is an example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1fcb5eaf5ba621014ab7635912b2bdc8/href">https://medium.com/media/1fcb5eaf5ba621014ab7635912b2bdc8/href</a></iframe><p>…and here is the resulting generated code</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6109e7ca554ab4786fe5e5e9c7ee7575/href">https://medium.com/media/6109e7ca554ab4786fe5e5e9c7ee7575/href</a></iframe><p>Beautiful, isn’t it? ❤️</p><p>Now if you have blocks inside other blocks you can rest assured that the indentation is kept in the generated code.</p><p>Now we have a valid code generator, but since you want these files generated at a build step, we will evaluate how we can associate the code generation to a phase of your build process.</p><h3>4. Integrating to popular tooling</h3><p>At this point, we can already extract data from a specification file (the properties file in this case) and put it in a template. All is left is to wire the input and outputs, you can do this via a CLI. But in the java world you usually end up with a fat jar for this CLI, and usually, they don’t play very nice with build tools since they don’t have life cycles. This is why I prefer Gradle plugins. There are plenty of resources of how you build a plugin, but it’s out of the scope of this article, however, I already built a demo plugin. For those who are curious <a href="https://github.com/brainya/typesafe-config/tree/master/tools/gradle-plugin">https://github.com/brainya/typesafe-config/tree/master/tools/gradle-plugin</a></p><p>It’s not published so don’t expect it to work in your project, but the <a href="https://github.com/brainya/typesafe-config/blob/master/tools/gradle-plugin/src/test/kotlin/com/brainya/typesafe/core/BuildLogicFunctionalTest.kt">functional test</a> already shows how it works and verifies its outputs.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/23cebbc4e891499b6a37f094e6771449/href">https://medium.com/media/23cebbc4e891499b6a37f094e6771449/href</a></iframe><p>…and that’s it! Every time you build your project, your files are generated, and you have your type-safe properties in the form of java classes. 🥳🥳🥳</p><h3>5. Wrapping it up 🎉</h3><p>So in this article, I took a very simple example where we extract transform and generate files, also I gave a sample code of how you can build a Gradle plugin. To make this task part of your build script, the example can be generalized for other use cases. For example here at <a href="https://medium.com/u/26cde32e6189">commercetools</a>, we use Raml specs instead of the properties file as a source of data to generate Rest API code. This allow us to ensure consistency in services since you have the spec as the source of truth for both documentation and code. If you are interested in this use case, please check <a href="https://github.com/vrapio/rmf-codegen">https://github.com/vrapio/rmf-codegen</a></p><p>Sample code for this article at <a href="https://github.com/brainya/typesafe-config">https://github.com/brainya/typesafe-config</a></p><p><em>Like what you read? follow me on </em><a href="https://www.linkedin.com/in/achraf-beniasaad-915bb44b/"><em>LinkedIn</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7f474e13427" width="1" height="1" alt=""><hr><p><a href="https://medium.com/commercetools-tech/ideas-on-writing-a-code-generator-b7f474e13427">Writing Your First Code Generator</a> was originally published in <a href="https://medium.com/commercetools-tech">commercetools tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>