<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Leonard Imbert, Author at Clever Cloud</title>
	<atom:link href="https://stagingv6.cleverapps.io/blog/author/imbert/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>From Code to Product</description>
	<lastBuildDate>Fri, 20 Mar 2015 15:32:00 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://staging-cc-assetsv6.cellar-c2.services.clever-cloud.com/uploads/2023/03/cropped-cropped-favicon-32x32.png</url>
	<title>Leonard Imbert, Author at Clever Cloud</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How I learned Scala in one month</title>
		<link>https://stagingv6.cleverapps.io/blog/engineering/2015/03/20/getting-started-with-scala/</link>
		
		<dc:creator><![CDATA[Leonard Imbert]]></dc:creator>
		<pubDate>Fri, 20 Mar 2015 15:32:00 +0000</pubDate>
				<category><![CDATA[Engineering]]></category>
		<category><![CDATA[Scala]]></category>
		<category><![CDATA[tutorial]]></category>
		<guid isPermaLink="false">https://www2.cleverapps.io/wp/blog/technology/2015/03/20/getting-started-with-scala/</guid>

					<description><![CDATA[<p><img width="1400" height="540" src="https://staging-cc-assetsv6.cellar-c2.services.clever-cloud.com/uploads/2021/08/getting-started-scala-1.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="" decoding="async" fetchpriority="high" srcset="https://staging-cc-assetsv6.cellar-c2.services.clever-cloud.com/uploads/2021/08/getting-started-scala-1.png 1400w, https://staging-cc-assetsv6.cellar-c2.services.clever-cloud.com/uploads/2021/08/getting-started-scala-1-300x116.png 300w, https://staging-cc-assetsv6.cellar-c2.services.clever-cloud.com/uploads/2021/08/getting-started-scala-1-1024x395.png 1024w, https://staging-cc-assetsv6.cellar-c2.services.clever-cloud.com/uploads/2021/08/getting-started-scala-1-768x296.png 768w, https://staging-cc-assetsv6.cellar-c2.services.clever-cloud.com/uploads/2021/08/getting-started-scala-1-1368x528.png 1368w" sizes="(max-width: 1400px) 100vw, 1400px" /></p><p>Hi, I’m Leonard. I have been an intern developer at Clever Cloud for one month now. When I came in, the CEO put me on a Scala project the first day. As a software engineer, there’s often a pressure to know everything, and I had never done scala before. My only experience in programming was html, php, javascript, and a little bit  of java. So I had to dive into this new language quite quickly.</p>
<span id="more-2795"></span>

<p>The thing is, Scala is a functional programming language. And the most brutal change was to learn this new paradigm. If you don&#39;t know what functional programming is, there is something you need to understand. In FP, the trick is to do everything only with functions (as in math function). Define the purest function that you can.</p>
<p>But you&#39;ll ask me, what is the interest of a pure function? A pure function is very useful because it can be tested separately, and especially because it&#39;s very reusable!</p>
<center>
  <figure>
    <img src="https://www2.cleverapps.io/app/uploads/2021/08/skyrim-vahala.gif">
    <figcaption>First steps towards the infinite beauty of pure functions</figcaption>
  </figure>
</center>

<h3 id="whats-a-pure-function">What’s a pure function?</h3>
<p>A pure function takes a value, returns an other value and does nothing else. For a given argument, it always returns the same result.  You don&#39;t want any side effect like database calls, etc. But there’s some help from the compiler: Scala has a strong static type system. Be sure the compiler will yell at you if you try to bypass it.</p>
<p>At first sight, Scala can look like an awful programming language, especially if you only code in javascript or php. But after a couple of weeks, by trying hard and being bashed a lot by the compiler, your code gets more and more structured. You finally get used to pure functions, and employ less and less side effects and mutating values.</p>
<p>After one month, I did not become a professional in Scala, but I’m now more and more comfortable with it and I find pleasure in coding. I began to integrate the abilities of FP principles and their great potential. Think about all the possibilities it can offer: it is almost endless.</p>
<h3 id="getting-started-with-scala">Getting started with Scala</h3>
<p>To learn scala, it’s useful to have some tooling in order to evaluate your code. Check the <a href="http://scala-lang.org">download page</a> to get typesafe activator. If you have a favorite IDE, I recommend to keep it. Else I personally use vim or sublime text, where Scala syntax highlighting works out of the box.</p>
<p>First, there is more than one way to learn scala. A good way is to look at concrete exercises. Try to rewrite a basic mathematical function or some exercises like this one.</p>
<p>&quot;I have x employees in my office. I want to have the sum of the salary of all Senior employees&quot;</p>
<p>First we need to create the <code>Employee</code> class</p>
<pre><code class="language-scala">case class Employee(name: String, title: String, salary: Int)
</code></pre>
<p>Then we create a list of these salary</p>
<pre><code class="language-scala">val employees: List[Employee] = List(
  Employee(&quot;Smith&quot;, &quot;Junior Developer&quot;, 1250),
  Employee(&quot;George&quot;, &quot;Senior Analyst&quot;, 2000),
  Employee(&quot;David&quot;, &quot;Cadet Developer&quot;, 1000),
  Employee(&quot;Bernard&quot;, &quot;Senior Developer&quot;, 2100),
  Employee(&quot;Clement&quot;, &quot;Senior Developer&quot;, 1850)
)
</code></pre>
<p>I then define a function which takes an <code>Employee</code> as a parameter, and returns true if the employee title begins with &quot;Senior&quot;.</p>
<pre><code class="language-scala">def isSenior(employee: Employee) = employee.title.startsWith(&quot;Senior&quot;)
</code></pre>
<p>Finally, we just apply <code>isSenior</code> on the list of employees to keep the senior employees, and then sum their salaries.</p>
<pre><code class="language-scala">val seniorSalaries =
   employees
     .filter(isSenior _)
     .map(_.salary)
     .sum
</code></pre>
<p>To explain, we apply the <code>filter</code> method to our list. <code>filter</code> is a native function which selects all elements which satisfy a predicate (here the <code>isSenior</code> function). Then we map over it. <code>map</code> transforms a list of elements of type A into a list of elements of type B, by applying a function from A to B to all its elements. Here, we transform a <code>List[Employee]</code> into a <code>List[Int]</code> by getting the salary of each employee. Finally, we do a sum on the list of salaries.</p>
<p>As you can see, we solved the problem with small pure functions. They are reusable regardless of the context and we were able to compose them with functions provided by the scala standard library.</p>
<p>If you want to dig deeper into Scala, check this <a href="http://manning.com/bjarnason/">book</a></p>
<p>If you have any questions, don’t hesitate to send me an email at <a href="mailto:&#108;&#101;&#111;&#x6e;&#97;&#114;&#100;&#46;&#105;&#x6d;&#98;&#101;&#x72;&#116;&#64;&#99;&#x6c;&#101;&#118;&#101;&#114;&#x2d;&#x63;&#108;&#111;&#117;&#x64;&#46;&#x63;&#x6f;&#x6d;">&#108;&#101;&#111;&#x6e;&#97;&#114;&#100;&#46;&#105;&#x6d;&#98;&#101;&#x72;&#116;&#64;&#99;&#x6c;&#101;&#118;&#101;&#114;&#x2d;&#x63;&#108;&#111;&#117;&#x64;&#46;&#x63;&#x6f;&#x6d;</a></p>
]]></description>
										<content:encoded><![CDATA[<p><img width="1400" height="540" src="https://staging-cc-assetsv6.cellar-c2.services.clever-cloud.com/uploads/2021/08/getting-started-scala-1.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="" decoding="async" srcset="https://staging-cc-assetsv6.cellar-c2.services.clever-cloud.com/uploads/2021/08/getting-started-scala-1.png 1400w, https://staging-cc-assetsv6.cellar-c2.services.clever-cloud.com/uploads/2021/08/getting-started-scala-1-300x116.png 300w, https://staging-cc-assetsv6.cellar-c2.services.clever-cloud.com/uploads/2021/08/getting-started-scala-1-1024x395.png 1024w, https://staging-cc-assetsv6.cellar-c2.services.clever-cloud.com/uploads/2021/08/getting-started-scala-1-768x296.png 768w, https://staging-cc-assetsv6.cellar-c2.services.clever-cloud.com/uploads/2021/08/getting-started-scala-1-1368x528.png 1368w" sizes="(max-width: 1400px) 100vw, 1400px" /></p><p>Hi, I’m Leonard. I have been an intern developer at Clever Cloud for one month now. When I came in, the CEO put me on a Scala project the first day. As a software engineer, there’s often a pressure to know everything, and I had never done scala before. My only experience in programming was html, php, javascript, and a little bit  of java. So I had to dive into this new language quite quickly.</p>
<span id="more-2795"></span>

<p>The thing is, Scala is a functional programming language. And the most brutal change was to learn this new paradigm. If you don&#39;t know what functional programming is, there is something you need to understand. In FP, the trick is to do everything only with functions (as in math function). Define the purest function that you can.</p>
<p>But you&#39;ll ask me, what is the interest of a pure function? A pure function is very useful because it can be tested separately, and especially because it&#39;s very reusable!</p>
<center>
  <figure>
    <img src="https://www2.cleverapps.io/app/uploads/2021/08/skyrim-vahala.gif">
    <figcaption>First steps towards the infinite beauty of pure functions</figcaption>
  </figure>
</center>

<h3 id="whats-a-pure-function">What’s a pure function?</h3>
<p>A pure function takes a value, returns an other value and does nothing else. For a given argument, it always returns the same result.  You don&#39;t want any side effect like database calls, etc. But there’s some help from the compiler: Scala has a strong static type system. Be sure the compiler will yell at you if you try to bypass it.</p>
<p>At first sight, Scala can look like an awful programming language, especially if you only code in javascript or php. But after a couple of weeks, by trying hard and being bashed a lot by the compiler, your code gets more and more structured. You finally get used to pure functions, and employ less and less side effects and mutating values.</p>
<p>After one month, I did not become a professional in Scala, but I’m now more and more comfortable with it and I find pleasure in coding. I began to integrate the abilities of FP principles and their great potential. Think about all the possibilities it can offer: it is almost endless.</p>
<h3 id="getting-started-with-scala">Getting started with Scala</h3>
<p>To learn scala, it’s useful to have some tooling in order to evaluate your code. Check the <a href="http://scala-lang.org">download page</a> to get typesafe activator. If you have a favorite IDE, I recommend to keep it. Else I personally use vim or sublime text, where Scala syntax highlighting works out of the box.</p>
<p>First, there is more than one way to learn scala. A good way is to look at concrete exercises. Try to rewrite a basic mathematical function or some exercises like this one.</p>
<p>&quot;I have x employees in my office. I want to have the sum of the salary of all Senior employees&quot;</p>
<p>First we need to create the <code>Employee</code> class</p>
<pre><code class="language-scala">case class Employee(name: String, title: String, salary: Int)
</code></pre>
<p>Then we create a list of these salary</p>
<pre><code class="language-scala">val employees: List[Employee] = List(
  Employee(&quot;Smith&quot;, &quot;Junior Developer&quot;, 1250),
  Employee(&quot;George&quot;, &quot;Senior Analyst&quot;, 2000),
  Employee(&quot;David&quot;, &quot;Cadet Developer&quot;, 1000),
  Employee(&quot;Bernard&quot;, &quot;Senior Developer&quot;, 2100),
  Employee(&quot;Clement&quot;, &quot;Senior Developer&quot;, 1850)
)
</code></pre>
<p>I then define a function which takes an <code>Employee</code> as a parameter, and returns true if the employee title begins with &quot;Senior&quot;.</p>
<pre><code class="language-scala">def isSenior(employee: Employee) = employee.title.startsWith(&quot;Senior&quot;)
</code></pre>
<p>Finally, we just apply <code>isSenior</code> on the list of employees to keep the senior employees, and then sum their salaries.</p>
<pre><code class="language-scala">val seniorSalaries =
   employees
     .filter(isSenior _)
     .map(_.salary)
     .sum
</code></pre>
<p>To explain, we apply the <code>filter</code> method to our list. <code>filter</code> is a native function which selects all elements which satisfy a predicate (here the <code>isSenior</code> function). Then we map over it. <code>map</code> transforms a list of elements of type A into a list of elements of type B, by applying a function from A to B to all its elements. Here, we transform a <code>List[Employee]</code> into a <code>List[Int]</code> by getting the salary of each employee. Finally, we do a sum on the list of salaries.</p>
<p>As you can see, we solved the problem with small pure functions. They are reusable regardless of the context and we were able to compose them with functions provided by the scala standard library.</p>
<p>If you want to dig deeper into Scala, check this <a href="http://manning.com/bjarnason/">book</a></p>
<p>If you have any questions, don’t hesitate to send me an email at <a href="mailto:&#108;&#101;&#111;&#x6e;&#97;&#114;&#100;&#46;&#105;&#x6d;&#98;&#101;&#x72;&#116;&#64;&#99;&#x6c;&#101;&#118;&#101;&#114;&#x2d;&#x63;&#108;&#111;&#117;&#x64;&#46;&#x63;&#x6f;&#x6d;">&#108;&#101;&#111;&#x6e;&#97;&#114;&#100;&#46;&#105;&#x6d;&#98;&#101;&#x72;&#116;&#64;&#99;&#x6c;&#101;&#118;&#101;&#114;&#x2d;&#x63;&#108;&#111;&#117;&#x64;&#46;&#x63;&#x6f;&#x6d;</a></p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
