<?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: Adrian Bornea</title>
    <description>The latest articles on DEV Community by Adrian Bornea (@adrianbornea).</description>
    <link>https://dev.to/adrianbornea</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%2F280316%2F58a1cdb7-b4c5-4324-9af5-a5c3e866dc4f.jpeg</url>
      <title>DEV Community: Adrian Bornea</title>
      <link>https://dev.to/adrianbornea</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/adrianbornea"/>
    <language>en</language>
    <item>
      <title>How to write functions in Kotlin? (Basic syntax)</title>
      <dc:creator>Adrian Bornea</dc:creator>
      <pubDate>Sat, 14 Dec 2019 18:25:38 +0000</pubDate>
      <link>https://dev.to/adrianbornea/how-to-write-functions-in-kotlin-basic-syntax-cf</link>
      <guid>https://dev.to/adrianbornea/how-to-write-functions-in-kotlin-basic-syntax-cf</guid>
      <description>&lt;p&gt;Functions are the building block of any programming language. They allow us to write DRY (Don't Repeat Yourself) code.&lt;/p&gt;

&lt;p&gt;Let's continue our Kotlin tutorial by exploring the elements of a function.&lt;/p&gt;

&lt;p&gt;We will start with a function that prints the current year. So it won't return anything.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;br&gt;
 fun printYear(): Unit {&lt;br&gt;
    println(2019)&lt;br&gt;&lt;br&gt;
}&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Let's examine each part:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;fun - the keyword that tells us that we are about to write a function&lt;/li&gt;
&lt;li&gt;printYear() - the name of the function&lt;/li&gt;
&lt;li&gt;: Unit - the return type. Unit is the equivalent of void in Java.&lt;/li&gt;
&lt;li&gt;{ } - the body of the function&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;NOTE: Unit is not required. Kotlin will allow us to write this function as:&lt;br&gt;
&lt;code&gt;&lt;br&gt;
 fun printYear() {&lt;br&gt;
    println(2019)&lt;br&gt;&lt;br&gt;
}&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now let's write a basic function that generates a team name based on the names of the players that compose that team. For example, if the players are named Adrian and Jacob, the name of the team will be AdrianJacobTeam.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;fun generateTeamName(firstName: String, secondName: String): String {&lt;br&gt;
    return firstName + secondName + "Team"&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Let's see what we have in addition to the previous function:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;(firstName: String, secondName: String) - The parameters needed to call the function. We declare them without var or val.&lt;/li&gt;
&lt;li&gt;return firstName + secondName + "Team" - if our function is not void it will have to contain the return statement (same type as the one declared)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Actually there also other types of functions, but we will analyze them one at a time.&lt;/p&gt;

&lt;p&gt;Photo by &lt;a href="https://pixabay.com/users/basitixustito-14594756/"&gt;basitixustito&lt;/a&gt;&lt;/p&gt;

</description>
      <category>kotlin</category>
      <category>android</category>
      <category>beginners</category>
      <category>dev</category>
    </item>
    <item>
      <title>How to declare a variable? Kotlin Tutorial</title>
      <dc:creator>Adrian Bornea</dc:creator>
      <pubDate>Fri, 13 Dec 2019 20:53:42 +0000</pubDate>
      <link>https://dev.to/adrianbornea/how-to-declare-a-variable-kotlin-tutorial-5b9a</link>
      <guid>https://dev.to/adrianbornea/how-to-declare-a-variable-kotlin-tutorial-5b9a</guid>
      <description>&lt;p&gt;A program is nothing without data. Let's find out how to declare a variable in Kotlin.&lt;br&gt;
Stop 🛑 Do you want to learn Kotlin with me? I will post multiple times per week new things I've learned about this programming language.&lt;/p&gt;

&lt;p&gt;There are two ways to declare a variable in Kotlin:&lt;/p&gt;

&lt;h1&gt;
  
  
  1. Using the "val" keyword
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;// constant, immutable, read-only &amp;amp; final&lt;br&gt;
val city: String = "Paris"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Basically once we declare it we can't change it.&lt;br&gt;
&lt;code&gt;city = "Rome" // will throw an error&lt;/code&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  2. Using the "var" keyword
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;// mutable variable&lt;br&gt;
var country: String = "Italy"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now we can re-use the same variable. We can mutate the object.&lt;br&gt;
&lt;code&gt;country = "France"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Kotlin is smart and can guess the type for a declared variable. I think this will make you a negligent programmer in the long run.&lt;br&gt;
&lt;code&gt;// type inference&lt;br&gt;
var language = "Java"&lt;br&gt;
// the compiler will know it's String&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once the type is established we can't change it&lt;br&gt;
&lt;code&gt;language = 12 // will throw an error&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I want these articles to be living entities, so I will edit them along the way with new/interesting I find about a particular subject.&lt;/p&gt;

&lt;p&gt;Image by &lt;a href="https://unsplash.com/@_ferh97"&gt;_ferh97&lt;/a&gt;&lt;/p&gt;

</description>
      <category>kotlin</category>
      <category>android</category>
      <category>beginners</category>
      <category>java</category>
    </item>
  </channel>
</rss>
