<?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" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Julialang - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Julialang - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Fri, 29 May 2026 10:35:24 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/julialang/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ Learn Julia by Coding 7 Projects – Hands-On Programming Tutorial ]]>
                </title>
                <description>
                    <![CDATA[ By Logan Kilpatrick The Julia programming language is used for a lot of really impactful and interesting challenges like Machine Learning and Data Science.  But before you can get to the complex stuff, it is worth exploring the basics to develop a so... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/learn-julia-by-coding-7-projects/</link>
                <guid isPermaLink="false">66d46015f855545810e93497</guid>
                
                    <category>
                        <![CDATA[ Julia ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Julialang ]]>
                    </category>
                
                    <category>
                        <![CDATA[ projects ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 28 Oct 2022 23:54:26 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/10/7-projects-1.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Logan Kilpatrick</p>
<p>The Julia programming language is used for a lot of really impactful and interesting challenges like Machine Learning and Data Science. </p>
<p>But before you can get to the complex stuff, it is worth exploring the basics to develop a solid foundation. </p>
<p>In this tutorial, we will go over some of the basics of Julia by building 7 small Julia projects:</p>
<ul>
<li>Mad Libs ✍️</li>
<li>Guess the Number Game 💯</li>
<li>Computer Number Guesser 🤖</li>
<li>Rock 🗿, Paper 📃, Scissors ✂️</li>
<li>Password Generator 🎫</li>
<li>Dice Rolling Simulator 🎲</li>
<li>Countdown Timer ⏱️</li>
</ul>
<p>If you have not downloaded Julia yet, head to: <a target="_blank" href="https://julialang.org/downloads/">https://julialang.org/downloads/</a> or watch this video:</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/t67TGcf4SmM" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<p>It's also worth noting that if you are totally new to Julia and want a comprehensive introduction to the language, you can <a target="_blank" href="https://www.freecodecamp.org/news/learn-julia-programming-language/">check out this freeCodeCamp article</a>.</p>
<h2 id="heading-beginner-friendly-julia-projects">Beginner-Friendly Julia Projects</h2>
<h3 id="heading-how-to-build-mad-libs-in-julia">How to Build Mad Libs in Julia ✍️</h3>
<p>In Mad Libs, the user is prompted to enter different types of words. The random words the user enters are then inserted into a sentence. This leads to some pretty wacky and funny outcomes. Let's try to program a simple version of this using Julia.</p>
<p>At the core of this problem, we want to concatenate (or add together) multiple strings so that we go from a sentence with some placeholders, to a sentence with the user input. </p>
<p>The simplest way to achieve this in Julia is with String Interpolation:</p>
<pre><code class="lang-julia">julia&gt; name = <span class="hljs-string">"Logan"</span>
<span class="hljs-string">"Logan"</span>

julia&gt; new_string = <span class="hljs-string">"Hello, my name is <span class="hljs-variable">$name</span>"</span>
<span class="hljs-string">"Hello, my name is Logan"</span>
</code></pre>
<p>Here we can see that we can insert the name variable we defined into the string by using the <code>$name</code> syntax.</p>
<p>There are a bunch of other ways to do this, like using the <code>string</code> function:</p>
<pre><code class="lang-julia">julia&gt; new_string = string(<span class="hljs-string">"Hello, my name is "</span>, name)
<span class="hljs-string">"Hello, my name is Logan"</span>
</code></pre>
<p>but string interpolation seems the most straightforward and readable in this case.</p>
<p>Now that we know how we are going to set up the strings, we need to prompt the user for their input. </p>
<p>To do this, we can use the <code>readline</code> function as follows:</p>
<pre><code class="lang-julia">julia&gt; my_name = readline()
Logan
<span class="hljs-string">"Logan"</span>
</code></pre>
<p>The <code>readline</code> function takes a single line of input from the user. This is exactly what we will want to use. Let’s put it all together into a simple example:</p>
<pre><code class="lang-julia"><span class="hljs-keyword">function</span> play_mad_libs()

    print(<span class="hljs-string">"Enter a verb (action): "</span>)
    verb1 = readline()

    print(<span class="hljs-string">"Enter an adjective (descriptive word): "</span>)
    adj1 = readline()

    print(<span class="hljs-string">"Enter a noun (person place or thing): "</span>)
    noun1 = readline()

    print(<span class="hljs-string">"Enter another noun (person place or thing): "</span>)
    noun2 = readline()

    print(<span class="hljs-string">"Enter a catchphrase (something like 'hands up!'): "</span>)
    phrase1 = readline()

    base_sentence = <span class="hljs-string">"John <span class="hljs-variable">$verb1</span> down the street one night, playing with his <span class="hljs-variable">$adj1</span> <span class="hljs-variable">$noun1</span>. When all of a / sudden, a <span class="hljs-variable">$noun2</span> jumped out at him and said <span class="hljs-variable">$phrase1</span>"</span>

    print(<span class="hljs-string">"\n\n"</span>, base_sentence)
<span class="hljs-keyword">end</span>

<span class="hljs-comment"># Link to source code: https://github.com/logankilpatrick/Julia-Projects-for-Beginners/blob/main/madlibs.jl</span>
</code></pre>
<p>In this example, we learned how to work with strings, define a function, use print statements, and more! </p>
<p>As noted before, there are lots of other ways to do the same things we did above. So if you want to find out more about working with strings, <a target="_blank" href="https://docs.julialang.org/en/v1/manual/strings/">check out the Julia docs here</a>.</p>
<h3 id="heading-how-to-build-a-guess-the-number-game-in-julia">How to Build a Guess the Number Game in Julia 💯</h3>
<p>In this game, we will have to generate a random number and then try to guess what it is. </p>
<p>To begin, we will need to generate a random number. As always, there are many ways to do something like this but the most straightforward approach is to do the following:</p>
<pre><code class="lang-julia">julia&gt; rand(<span class="hljs-number">1</span>:<span class="hljs-number">10</span>)
<span class="hljs-number">4</span>
</code></pre>
<p>The <code>rand</code> function takes as input the range of numbers you want to use as the bounds for the number you will generate. In this case, we set the range as <code>1-10</code>, inclusive of both numbers.</p>
<p>The other new topic we need to cover for this example to work is while loops. The basic structure of a while loop is:</p>
<pre><code class="lang-julia"><span class="hljs-keyword">while</span> some_condition is <span class="hljs-literal">true</span>
   <span class="hljs-keyword">do</span> something
<span class="hljs-keyword">end</span>
</code></pre>
<p>This loop will continue to iterate until the condition for the while loop is no longer met. You will see how we use this soon to keep prompting the user to enter a number until they guess it right.</p>
<p>Lastly, to make it a little easier for us, we are going to add an if statement which tells us if we guess a number that is close to the target number. The structure of an if statement in Julia is:</p>
<pre><code class="lang-julia"><span class="hljs-keyword">if</span> some_condition is <span class="hljs-literal">true</span>
   <span class="hljs-keyword">do</span> something
<span class="hljs-keyword">end</span>
</code></pre>
<p>The big difference is that the if statement is checked once and then it is done. The initial condition is not re-checked unless the if statement is in a loop.</p>
<p>Now that we have the basic ideas down, let's see the actual code to build the number guesser. Make sure you try this on your own before checking the solution below. Happy coding! 🎉</p>
<pre><code class="lang-julia"><span class="hljs-comment"># Number Guessing Game in Julia</span>
<span class="hljs-comment"># Source: https://github.com/logankilpatrick/10-Julia-Projects-for-Beginners</span>

<span class="hljs-keyword">function</span> play_number_guess_human()

    total_numbers = <span class="hljs-number">25</span> <span class="hljs-comment"># </span>

    <span class="hljs-comment"># Generate a random number within a certain range</span>
    target_number = rand(<span class="hljs-number">1</span>:total_numbers)
    guess = <span class="hljs-number">0</span>

    <span class="hljs-comment"># While the number has not been guessed, keep prompting for guesses</span>
    <span class="hljs-keyword">while</span> guess != target_number
        print(<span class="hljs-string">"Please guess a number between 1 and <span class="hljs-variable">$total_numbers</span>: "</span>)
        guess = parse(<span class="hljs-built_in">Int64</span>, readline())
        <span class="hljs-comment"># Convert the string value input to a number</span>

        <span class="hljs-comment"># If we are within +/-2 of the target, give a hint</span>
        <span class="hljs-keyword">if</span> abs(target_number - guess) &lt;= <span class="hljs-number">2</span> &amp;&amp; target_number != guess
            print(<span class="hljs-string">"\nYou are getting closer!\n"</span>)
        <span class="hljs-keyword">end</span>
    <span class="hljs-keyword">end</span>

    print(<span class="hljs-string">"Nice job, you got it!"</span>)
<span class="hljs-keyword">end</span>
</code></pre>
<h3 id="heading-how-to-build-a-computer-number-guesser-in-julia">How to Build a Computer Number Guesser in Julia 🤖</h3>
<p>Now that we have seen what it looks like for us to try and guess what the computer randomly generated, let's see if the computer can do any better. </p>
<p>In this game, we will select a number and then see how long it takes the computer to guess that number. To do this, we will introduce some new concepts like the Random module and for loops.</p>
<p>We'll begin by thinking about how we can have the computer guess random numbers without repeating any. </p>
<p>One simple solution is to use the <code>rand</code> function, but the issue is that there’s no built-in way to make sure the computer doesn’t guess the same number more than once – since, after all, it is random!</p>
<p>We can solve this issue by combining the <code>collect</code> function and the <code>shuffle</code> function. We begin by defining a random seed:</p>
<pre><code class="lang-julia">julia&gt; rng = <span class="hljs-built_in">MersenneTwister</span>(<span class="hljs-number">1234</span>);
</code></pre>
<p>Random seeds make it so that random number generators make reproducible results. Next, we need to define all possible guesses:</p>
<pre><code class="lang-julia">julia&gt; a = collect(<span class="hljs-number">1</span>:<span class="hljs-number">50</span>)
<span class="hljs-number">50</span>-element <span class="hljs-built_in">Vector</span>{<span class="hljs-built_in">Int64</span>}:
<span class="hljs-number">1</span>
<span class="hljs-number">2</span>
<span class="hljs-number">3</span>
⋮
</code></pre>
<p>We now need to use the <code>shuffle</code> function to make the guesses random:</p>
<pre><code class="lang-julia">julia&gt; <span class="hljs-keyword">using</span> Random
julia&gt; shuffle(rng, a)
<span class="hljs-number">50</span>-element <span class="hljs-built_in">Vector</span>{<span class="hljs-built_in">Int64</span>}:
<span class="hljs-number">41</span>
<span class="hljs-number">23</span>
<span class="hljs-number">13</span>
<span class="hljs-number">49</span>
⋮
</code></pre>
<p>Now that we have the random guesses set up, it's time to loop through them one at a time and see if the number is equal to the target the user inputted. </p>
<p>Again, give this a try before you check out the solution below:</p>
<pre><code class="lang-julia"><span class="hljs-comment"># Computer Number Guessing Game in Julia</span>
<span class="hljs-comment"># Source: https://github.com/logankilpatrick/10-Julia-Projects-for-Beginners</span>

<span class="hljs-keyword">using</span> Random

<span class="hljs-keyword">function</span> play_number_guess_computer()

    print(<span class="hljs-string">"Please enter a number between 1 and 50 for the computer to try and guess: "</span>)

    <span class="hljs-comment"># Take in the user input and convert it to a number</span>
    target_number = parse(<span class="hljs-built_in">Int64</span>, readline())

    <span class="hljs-comment"># Create an array of 50 numbers</span>
    guess_order = collect(<span class="hljs-number">1</span>:<span class="hljs-number">50</span>)

    <span class="hljs-comment"># Define our random seed</span>
    rng = <span class="hljs-built_in">MersenneTwister</span>(<span class="hljs-number">1234</span>)

    <span class="hljs-comment"># Shuffle the array randomly given our seed</span>
    shuffled_guess = shuffle(rng, guess_order)

    <span class="hljs-comment"># Loop through each guess and see if it's right</span>
    <span class="hljs-keyword">for</span> guess <span class="hljs-keyword">in</span> shuffled_guess

        <span class="hljs-keyword">if</span> guess == target_number
            print(<span class="hljs-string">"\nThe computer cracked the code and guessed it right!"</span>)
            <span class="hljs-keyword">break</span> <span class="hljs-comment"># Stop the for loop if we get it right</span>
        <span class="hljs-keyword">end</span>

        print(<span class="hljs-string">"\nComputer guessed: <span class="hljs-variable">$guess</span>"</span>)
    <span class="hljs-keyword">end</span>
<span class="hljs-keyword">end</span>
</code></pre>
<h3 id="heading-how-to-build-rock-paper-scissors-in-julia">How to Build Rock 🗿, Paper 📃, Scissors ✂️ in Julia</h3>
<p>If you have never played rock, paper, scissors, you are missing out! The basic gist is you try to beat your opponent with either rock, paper, or scissors. </p>
<p>In this game, rock beats scissors, scissors beat paper, and paper beats rock. If two people do the same one, you go again.</p>
<p>In this example, we will be playing rock, paper, scissors against the computer. We will also use the <code>sleep</code> function to introduce a short delay as if someone was saying the words out loud (which you would do if you played in person).</p>
<p>The sleep function takes in a number that represents how long you want (in seconds) to sleep. We can use this with a function or a loop to slow things down as you will see in this game.</p>
<pre><code class="lang-julia">sleep(<span class="hljs-number">1</span>) <span class="hljs-comment"># Sleep for 1 second</span>
</code></pre>
<p>Let's also explore a function I found while writing this tutorial, <code>Base.prompt</code> , which helps us do what we were previously using <code>readline</code> for. </p>
<p>In this case, however, <code>prompt</code> auto-appends a <code>:</code> to the end of the line and allows us to avoid having two separate lines for the print and user input:</p>
<pre><code class="lang-julia">human_move = Base.prompt(<span class="hljs-string">"Please enter 🗿, 📃, or ✂️"</span>)
</code></pre>
<p>We will also need to use an <code>elseif</code> to make this example game work. We can chain <code>if</code> , <code>elseif</code> , and <code>else</code> together for completeness. Try putting together the if conditionals, prompts, and sleeps to get the desired behavior, and then check out the code below:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/1-406j3f0e3nN-VxRJUUtK7A.gif" alt="Image" width="600" height="400" loading="lazy">
<em>Gif of playing Rock Paper Scissors in the Julia REPL</em></p>
<pre><code class="lang-julia"><span class="hljs-comment"># Rock 🗿, Paper 📃, Scissors ✂️ Game in Julia</span>

<span class="hljs-keyword">function</span> play_rock_paper_scissors()
    moves = [<span class="hljs-string">"🗿"</span>, <span class="hljs-string">"📃"</span>, <span class="hljs-string">"✂️"</span>]
    computer_move = moves[rand(<span class="hljs-number">1</span>:<span class="hljs-number">3</span>)]

    <span class="hljs-comment"># Base.prompt is similar to readline which we used before</span>
    human_move = Base.prompt(<span class="hljs-string">"Please enter 🗿, 📃, or ✂️"</span>)
    <span class="hljs-comment"># Appends a ": " to the end of the line by default</span>

    print(<span class="hljs-string">"Rock..."</span>)
    sleep(<span class="hljs-number">0.8</span>)

    print(<span class="hljs-string">"Paper..."</span>)
    sleep(<span class="hljs-number">0.8</span>)

    print(<span class="hljs-string">"Scissors..."</span>)
    sleep(<span class="hljs-number">0.8</span>)

    print(<span class="hljs-string">"Shoot!\n"</span>)

    <span class="hljs-keyword">if</span> computer_move == human_move
        print(<span class="hljs-string">"You tied, please try again"</span>)
    <span class="hljs-keyword">elseif</span> computer_move == <span class="hljs-string">"🗿"</span> &amp;&amp; human_move == <span class="hljs-string">"✂️"</span>
        print(<span class="hljs-string">"You lose, the computer won with 🗿, please try again"</span>)
    <span class="hljs-keyword">elseif</span> computer_move == <span class="hljs-string">"📃"</span> &amp;&amp; human_move == <span class="hljs-string">"🗿"</span>
        print(<span class="hljs-string">"You lose, the computer won with 📃, please try again"</span>)
    <span class="hljs-keyword">elseif</span> computer_move == <span class="hljs-string">"✂️"</span> &amp;&amp; human_move == <span class="hljs-string">"📃"</span>
        print(<span class="hljs-string">"You lose, the computer won with ✂️, please try again"</span>)
    <span class="hljs-keyword">else</span>
        print(<span class="hljs-string">"You won, the computer lost with <span class="hljs-variable">$computer_move</span>, nice work!"</span>)
    <span class="hljs-keyword">end</span>

<span class="hljs-keyword">end</span>
</code></pre>
<h3 id="heading-how-to-build-a-password-generator-in-julia">How to Build a Password Generator in Julia 🎫</h3>
<p><strong>WARNING: Do not use this code to generate real passwords!</strong></p>
<p>In the age of endless data breaches and people using the same password for every website, having a secure password is important. In this example, we will generate an arbitrary number of passwords with a variable length. </p>
<p>Given that this could take a long time, we will also add an external package, <a target="_blank" href="https://github.com/cloud-oak/ProgressBars.jl">ProgressBars.jl</a>, to visually show the progress of our for loop. If you have never added an external package before, consider <a target="_blank" href="https://blog.devgenius.io/the-most-underrated-feature-of-the-julia-programming-language-the-package-manager-652065f45a3a">checking out this robust tutorial</a> on why the package manager is the most underrated feature of the Julia programming language.</p>
<p>To add a Julia package, open the REPL and type <code>]</code> followed by <code>add ProgressBars</code>. After that, as we did with the Random module (note we did not need to add it since it is part of base Julia), we can say <code>using ProgressBars</code> to load it in.</p>
<p>The main new idea we will introduce here is vectors / arrays. In Julia, we can put any type into an array. To create an empty array, we do:</p>
<pre><code class="lang-julia">password_holder = []
</code></pre>
<p>and then to add something, we use the <code>push!</code> function as you will see in the below example. </p>
<p>As mentioned before, we will use the ProgressBars package to show progress on the screen. Note that Julia is so quick that it likely won’t show you the loading screen unless you manually slow things down with a sleep function call or a high number of passwords. Check out the README for an example of using this in practice. </p>
<p>As with the other example, try to put some code together before you dissect the example below:</p>
<pre><code class="lang-julia"><span class="hljs-comment"># Generate Passwords in Julia</span>
<span class="hljs-comment"># Source: https://github.com/logankilpatrick/10-Julia-Projects-for-Beginners</span>
<span class="hljs-keyword">using</span> ProgressBars
<span class="hljs-keyword">using</span> Random

<span class="hljs-comment"># WARNING: Do not use this code to generate actual passwords!</span>
<span class="hljs-keyword">function</span> generate_passwords()
    num_passwords = parse(<span class="hljs-built_in">Int64</span>, Base.prompt(<span class="hljs-string">"How many passwords do you want to generate?"</span>))
    password_length = parse(<span class="hljs-built_in">Int64</span>, Base.prompt(<span class="hljs-string">"How long should each password be?"</span>))

    <span class="hljs-comment"># Create an empty vector / array</span>
    password_holder = []

    <span class="hljs-comment"># Generate a progress bar to show how close we are to being done</span>
    <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> ProgressBar(<span class="hljs-number">1</span>:num_passwords)
        <span class="hljs-comment"># Add the new password into the password holder</span>
        push!(password_holder, randstring(password_length))
        sleep(<span class="hljs-number">0.2</span>) <span class="hljs-comment"># Manually slowdown the generation of passwords</span>
    <span class="hljs-keyword">end</span>

    <span class="hljs-comment"># Only show the passwords if there are less than 100</span>
    <span class="hljs-keyword">if</span> length(password_holder) &lt;= <span class="hljs-number">100</span>
        <span class="hljs-comment"># Loop through each password one by one</span>
        <span class="hljs-keyword">for</span> password <span class="hljs-keyword">in</span> password_holder
            print(<span class="hljs-string">"\n"</span>, password)
        <span class="hljs-keyword">end</span>
    <span class="hljs-keyword">end</span>
<span class="hljs-keyword">end</span>
</code></pre>
<h3 id="heading-how-to-build-a-dice-rolling-simulator-in-julia">How to Build a Dice Rolling Simulator in Julia 🎲</h3>
<p>Dice are a fun way to explore and play around with randomness along with unicode characters. </p>
<p>Julia has amazing support for unicode, and if you want to see all the characters it supports, <a target="_blank" href="https://docs.julialang.org/en/v1/manual/unicode-input/">head to the Julia docs</a>. </p>
<p>Let's begin by defining an array of dice faces. To access unicode characters, we can use the Julia REPL to do tab completion by typing the following:</p>
<pre><code class="lang-julia">julia&gt; \dicei
</code></pre>
<p>followed by the tab button. This will create <code>⚀</code> which is "Die Face-1". If we do this for all 6 sides of a 6 sided die, we end up with:</p>
<pre><code class="lang-julia">dice_faces = [<span class="hljs-string">"⚀"</span>, <span class="hljs-string">"⚁"</span>, <span class="hljs-string">"⚂"</span>, <span class="hljs-string">"⚃"</span>, <span class="hljs-string">"⚄"</span>, <span class="hljs-string">"⚅"</span>]
</code></pre>
<p>For this game, we want to continually ask the user if they want to roll the dice. If they do, we generate a random number between 1 and 6 and then display the dice face from the array we created above. </p>
<p>Just like we did in previous projects, we will want to use the <code>rand</code> function as follows:</p>
<pre><code class="lang-julia">rand(<span class="hljs-number">1</span>:num_sides_dice)
</code></pre>
<p>Give this a try before you check out one possible solution that is highlighted below and keep in mind how we could extend this or use this code to program a much larger game like Monopoly. </p>
<pre><code class="lang-julia"><span class="hljs-comment"># Code from https://github.com/logankilpatrick/Julia-Projects-for-Beginners</span>

<span class="hljs-keyword">function</span> rolling_dice()

    <span class="hljs-comment"># Number of sides for dice</span>
    num_sides_dice = <span class="hljs-number">6</span>

    <span class="hljs-comment"># While the user wants to roll a die, continue to generate a number between 1 and the number of sides</span>
    dice_faces = [<span class="hljs-string">"⚀"</span>, <span class="hljs-string">"⚁"</span>, <span class="hljs-string">"⚂"</span>, <span class="hljs-string">"⚃"</span>, <span class="hljs-string">"⚄"</span>, <span class="hljs-string">"⚅"</span>]

    <span class="hljs-keyword">while</span> <span class="hljs-literal">true</span>
        print(<span class="hljs-string">"Do you want to roll a dice? (1=Yes/0=No): "</span>)
        guess = parse(<span class="hljs-built_in">Int64</span>, readline())
        <span class="hljs-comment"># Convert the string value input to a number</span>

        <span class="hljs-keyword">if</span> guess == <span class="hljs-number">1</span>
            println(<span class="hljs-string">"Rolling dice"</span>)
            current_side = rand(<span class="hljs-number">1</span>:num_sides_dice)
            println(<span class="hljs-string">"Dice has number <span class="hljs-subst">$(dice_faces[current_side])</span>"</span>)
        <span class="hljs-keyword">elseif</span> guess == <span class="hljs-number">0</span>
            println(<span class="hljs-string">"Exiting"</span>)
            <span class="hljs-keyword">break</span> <span class="hljs-comment"># Stop the while loop if the user decides to do so</span>
        <span class="hljs-keyword">else</span>
            println(<span class="hljs-string">"Invalid input, please try again"</span>)
        <span class="hljs-keyword">end</span> 
    <span class="hljs-keyword">end</span>

<span class="hljs-keyword">end</span>
</code></pre>
<h3 id="heading-how-to-build-a-countdown-timer-in-julia">How to Build a Countdown Timer in Julia⏱️</h3>
<p>Countdowns, for better or worse, are a huge part of life. From New Years Eve to a parent frustratingly trying to convince a child to obey some rule, we see and participate in countdown timers regularly. </p>
<p>Now, we are going to get a chance to program one (yay). At the core, we will again be using the <code>sleep</code> function which we had a chance to play around with in the rock paper scissors example.</p>
<p>As a quick reminder, <code>sleep</code> takes in as an argument the number of seconds we want the program to pause for. </p>
<p>For this example, we are going to try to do some while loop nesting by using functions. We want to have a loop that continues to prompt the user if they want to set a timer, and then if they do, we call a function called <code>run_timer</code>. The <code>run_timer</code> function should prompt the user to enter how long they want the timer to run for. </p>
<p>The caveat here is that we also want to print our how long is left for the timer on each iterations. So if the user enters 5, we can't just do <code>sleep(5)</code> since the user won't be able to see anything happen for those 5 seconds. </p>
<p>Below is the main function which is given to you to start. Feel free to modify this as you see fit. Use this starter code and then define the <code>run_timer</code> function per the specification above. </p>
<p>Remember, there's a lot of possible ways to approach this and the solution we include at the bottom is just one possible approach.</p>
<pre><code class="lang-julia"><span class="hljs-comment"># Code from: https://github.com/logankilpatrick/Julia-Projects-for-Beginners</span>

<span class="hljs-keyword">function</span> run_timer()
    <span class="hljs-comment"># TODO</span>
<span class="hljs-keyword">end</span>

<span class="hljs-comment"># Call the run_timer function in a loop until the user quits it</span>
<span class="hljs-keyword">function</span> countdown_timer()

    <span class="hljs-comment"># While the user chooses to run the countdown timer</span>
    <span class="hljs-keyword">while</span> <span class="hljs-literal">true</span>
        print(<span class="hljs-string">"Do you want set a countdown timer? (1=Yes/0=No): "</span>)
        answer = parse(<span class="hljs-built_in">Int64</span>, readline())
        <span class="hljs-comment"># Convert the string value input to a number</span>

        <span class="hljs-keyword">if</span> answer == <span class="hljs-number">1</span>
            <span class="hljs-comment"># Run the timer</span>
            run_timer()
        <span class="hljs-keyword">elseif</span> answer == <span class="hljs-number">0</span>
            println(<span class="hljs-string">"Exiting..."</span>)
            <span class="hljs-keyword">break</span> <span class="hljs-comment"># Stop the countdown timer</span>
        <span class="hljs-keyword">else</span>
            println(<span class="hljs-string">"Invalid input, please try again"</span>)
        <span class="hljs-keyword">end</span> 
    <span class="hljs-keyword">end</span>

<span class="hljs-keyword">end</span>
countdown_timer()
</code></pre>
<p>Give it a shot and remember you will need to make use of the <code>parse</code>, <code>readline</code>, <code>sleep</code>, and <code>println</code> functions to make this function work. </p>
<pre><code class="lang-julia"><span class="hljs-comment"># Code from: https://github.com/logankilpatrick/Julia-Projects-for-Beginners</span>

<span class="hljs-keyword">function</span> run_timer()
    print(<span class="hljs-string">"Enter the amount of seconds: "</span>)
    seconds = parse(<span class="hljs-built_in">Int64</span>, readline())

    println(<span class="hljs-string">"Countdown starts now with <span class="hljs-variable">$seconds</span> seconds remaining."</span>)
    current_seconds = seconds

    <span class="hljs-comment"># While the countdown timer is not finished</span>
    <span class="hljs-keyword">while</span> current_seconds != <span class="hljs-number">0</span>

        <span class="hljs-comment"># Print the current countdown</span>
        <span class="hljs-keyword">if</span> current_seconds != seconds
            println(<span class="hljs-string">"Seconds left: <span class="hljs-variable">$current_seconds</span>"</span>)
        <span class="hljs-keyword">end</span>

        <span class="hljs-comment"># Wait for one second</span>
        sleep(<span class="hljs-number">1</span>)
        current_seconds = current_seconds - <span class="hljs-number">1</span>
    <span class="hljs-keyword">end</span>
    println(<span class="hljs-string">"The countdown is over!"</span>)
<span class="hljs-keyword">end</span>

<span class="hljs-comment"># Call the run_timer function in a loop until the user quits it</span>
<span class="hljs-keyword">function</span> countdown_timer()

    <span class="hljs-comment"># While the user chooses to run the countdown timer</span>
    <span class="hljs-keyword">while</span> <span class="hljs-literal">true</span>
        print(<span class="hljs-string">"Do you want set a countdown timer? (1=Yes/0=No): "</span>)
        answer = parse(<span class="hljs-built_in">Int64</span>, readline())
        <span class="hljs-comment"># Convert the string value input to a number</span>

        <span class="hljs-keyword">if</span> answer == <span class="hljs-number">1</span>
            <span class="hljs-comment"># Run the timer</span>
            run_timer()
        <span class="hljs-keyword">elseif</span> answer == <span class="hljs-number">0</span>
            println(<span class="hljs-string">"Exiting..."</span>)
            <span class="hljs-keyword">break</span> <span class="hljs-comment"># Stop the countdown timer</span>
        <span class="hljs-keyword">else</span>
            println(<span class="hljs-string">"Invalid input, please try again"</span>)
        <span class="hljs-keyword">end</span> 
    <span class="hljs-keyword">end</span>

<span class="hljs-keyword">end</span>

countdown_timer()
</code></pre>
<h2 id="heading-wrapping-up">Wrapping up 🎁</h2>
<p>I hope you had as much fun working with and reading about these projects as I did creating them. </p>
<p>If you want to make your own version of this post and make some small Julia projects and share them with the world, please do so and open a PR here: <a target="_blank" href="https://github.com/logankilpatrick/10-Julia-Projects-for-Beginners">https://github.com/logankilpatrick/10-Julia-Projects-for-Beginners</a>. </p>
<p>I can easily change the repo name to accommodate an influx of small projects.</p>
<p>I will also note that an exercise like this is also a great way to potentially contribute to Julia. While I was working on this post, I was able to open 2 PR’s to base Julia which I think will help improve the developer experience:</p>
<ul>
<li><a target="_blank" href="https://github.com/JuliaLang/julia/pull/43635">https://github.com/JuliaLang/julia/pull/43635</a> and</li>
<li><a target="_blank" href="https://github.com/JuliaLang/julia/pull/43640">https://github.com/JuliaLang/julia/pull/43640</a>.</li>
</ul>
<p>If you enjoyed this tutorial, <a target="_blank" href="https://twitter.com/OfficialLoganK">let’s connect on Twitter</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Use Linear Models and Decision Trees in Julia ]]>
                </title>
                <description>
                    <![CDATA[ By Logan Kilpatrick As a machine learning engineer or data scientist, one of the most critical decisions you can make is what type of model to use to solve a specific problem. Do you really need to use Deep Learning to model this specific problem? Wi... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/linear-models-vs-decision-trees-in-julia/</link>
                <guid isPermaLink="false">66d4601947a8245f78752a8d</guid>
                
                    <category>
                        <![CDATA[ data analysis ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Data Science ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Julia ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Julialang ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Machine Learning ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 29 Aug 2022 13:46:21 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/08/LinearModels-1.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Logan Kilpatrick</p>
<p>As a machine learning engineer or data scientist, one of the most critical decisions you can make is what type of model to use to solve a specific problem.</p>
<p>Do you really need to use Deep Learning to model this specific problem? Will something like a Random Forest model or Decision Tree be more effective? </p>
<p>While sometimes the best thing to do is try things out and see for yourself, there is some context that you should be aware of as you specifically evaluate a Linear Model vs a Decision Tree. </p>
<p><strong>🚨 TL;DR</strong> – Linear models are good when the data itself has a linear relationship. Decision trees, on the other hand, are helpful since they can model more complex classification or regression problems with non-linear relationships in an explainable way.</p>
<p>Let's dive deeper into why this is the case.</p>
<h2 id="heading-what-is-a-linear-model">What is a Linear model? 🤔</h2>
<p>The term linear model has many different meanings since it is used across multiple domains including, in our case, machine learning (ML). </p>
<p>In the world of ML, Linear Models refer to a specific class of models where the goal is to map the relationship between the input value(s) and some outcome, usually where there is a linear relationship present (more on this later). </p>
<p>A classic example of this is predicting the price of a house based on different attributes (often called "features" in ML) such as square footage, the number of bedrooms, the year it was built, and so on. </p>
<p>The most commonly used Linear model is Linear Regression (LR) where the model essentially becomes a line of best fit for the data that you can plot as shown below. </p>
<p>In LR, the main goal is to predict some numerical value, which is different than the goal of a classification model. In classification, we want to predict the class that some input data maps to which can often times be a more straightforward problem to model.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/08/linear.png" alt="Graph showing a linear relationship " width="600" height="400" loading="lazy">
<em>Example of linear regression. Image by Author</em></p>
<p>Just like in other forms of ML, we train the Linear model by giving it training input and output data which is used to set the models weights. Since this method requires the use of labeled data, it is a supervised learning problem.</p>
<p>So when would I use an LR model? The general rule of thumb is that LR models only work when we are modeling some type of relationship that is itself linear. </p>
<h2 id="heading-understanding-linear-relationships">Understanding Linear Relationships</h2>
<p>So the next logical question is, "How do I know if the data I am working with has a linear relationship". </p>
<p>Before we answer this, it is worth pointing out that intimate knowledge of the data you are working with in any particular ML problem is likely what will make you most successful at solving the problem. </p>
<p>In the "real world", engineers and scientists spend close to 80% of their time working with data, and only 20% of their time actually solving problems (which is an issue in and of itself, but this is the reality at the moment). </p>
<p>Okay, so back to linear relationships in data and how we know if that exists for our dataset. The most straightforward way to test this is by simply plotting the data and looking at it. </p>
<p>If you see a plot like the one depicted above, you are all set since the relationship appears to be linear. </p>
<p>If you see a plot like the one below, you might not be able to use LR.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/08/non-linear-2.png" alt="Graph showing a non-linear relationship" width="600" height="400" loading="lazy">
<em>Non-linear data. Image by Author</em></p>
<p>Next, let's look at a Linear Regression model in Julia. If you are not familiar with Julia, you might want to check out my "<strong><a target="_blank" href="https://www.freecodecamp.org/news/learn-julia-programming-language/">Learn Julia For Beginners</a>"</strong> right here on freeCodeCamp.</p>
<h2 id="heading-linear-regression-in-action">Linear Regression in Action 📣</h2>
<p>Let's use the basic housing example I mentioned before. You can download the data from <a target="_blank" href="https://raw.githubusercontent.com/julia4ta/tutorials/master/Series%2005/Files/housingdata.csv">this link</a>. We can create a new Julia file and add the following imports:</p>
<pre><code class="lang-julia"><span class="hljs-keyword">using</span> GLM, Plots, TypedTables, CSV
</code></pre>
<p>The key package here is <a target="_blank" href="https://github.com/JuliaStats/GLM.jl">GLM.jl</a> which stands for Generalized linear models in Julia. It will help us make the initial LR model! Plots.jl, TypedTables.jl, and CSV.jl all play a supporting role in helping us with this example. </p>
<p>The next step is to use CSV.jl to load in the dataset and then set up our X and Y values:</p>
<pre><code class="lang-julia">housing_data = CSV.File(<span class="hljs-string">"housingdata.csv"</span>)

X = housing_data.size

Y = housing_data.price

<span class="hljs-comment"># Setup a Typed Table</span>
t = Table(X = X, Y = Y)
</code></pre>
<p>Next, we will plot the data to make sure that it looks like there is a linear relationship present: </p>
<pre><code class="lang-julia"><span class="hljs-comment"># Use Plots package to generate scatter plot of data</span>
gr(size = (<span class="hljs-number">600</span>, <span class="hljs-number">600</span>))

<span class="hljs-comment"># Create scatter plot</span>
p_scatter = scatter(X, Y,
    xlims = (<span class="hljs-number">0</span>, <span class="hljs-number">5000</span>),
    ylims = (<span class="hljs-number">0</span>, <span class="hljs-number">800000</span>),
    xlabel = <span class="hljs-string">"Size in square feet"</span>,
    ylabel = <span class="hljs-string">"Price of the house"</span>,
    title = <span class="hljs-string">"Housing Prices example freeCodeCamp"</span>,
    legend = <span class="hljs-literal">false</span>,
    color = :red
)
</code></pre>
<p>This will generate a plot that looks like this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/08/plot_5.svg" alt="Plot of housing prices showing a linear relationship between size and price" width="600" height="400" loading="lazy">
<em>Image by Author</em></p>
<p>We can see that the relationship appears to be linear in this case which means we can proceed with building a basic model. </p>
<p>GLM provides two basic ways of fitting models, you can <a target="_blank" href="https://juliastats.org/GLM.jl/stable/#Fitting-GLM-models">read about this in the docs</a>. For our example, we will use the first option which looks like this:</p>
<pre><code class="lang-julia">lm(formula, data)
</code></pre>
<p>where formula means the following:</p>
<blockquote>
<p><code>formula</code>: a <a target="_blank" href="https://juliastats.org/StatsModels.jl/stable/formula/">StatsModels.jl <code>Formula</code> object</a> referring to columns in <code>data</code>; for example, if column names are <code>:Y</code>, <code>:X1</code>, and <code>:X2</code>, then a valid formula is <code>@formula(Y ~ X1 + X2)</code></p>
</blockquote>
<p>So in our case, since we only have 1 column (the size of the house), our formula will look like this: </p>
<pre><code class="lang-julia">ols = lm(<span class="hljs-meta">@formula</span>(Y ~ X), t)
</code></pre>
<p>And again we pass in the <code>t</code> variable which is the data we want to fit the model to. </p>
<p>After that, we can try plotting the new fit model onto the initial graph to see what it looks like and if it is modeling the data correctly.</p>
<pre><code class="lang-julia">plot!(X, predict(ols), color = :green, linewidth = <span class="hljs-number">3</span>)
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/08/plot_6.svg" alt="Housing price graph showing the linear regression model is correctly fitting to the data" width="600" height="400" loading="lazy">
<em>Image by Author</em></p>
<p>We can see from the above image that we are correctly fitting the model to the data which means we did it! We have successfully created our Linear Regression model in Julia.</p>
<p>Let's do one more quick test to see if we can use the model on some new data for a house with only 750 square feet:</p>
<pre><code class="lang-julia">small_house = Table(X = [<span class="hljs-number">750</span>])

predict(ols, small_house)
</code></pre>
<p>The model predicts that the house will cost <code>172164.45</code> which looks right when we observe the graph above (despite most data being for houses with more than 1,000 square feet).</p>
<h2 id="heading-wrapping-up-linear-regression">Wrapping up Linear Regression 🎀</h2>
<p>We have just completed our whirlwind tour of linear models in Julia. We talked about why you might want to use them, the constraints (the relationship must be linear), how to check if the relationship is linear, and how to fit an LR in Julia. </p>
<p>I hope this helped frame the context for when you might want to use one of these models as well as how you would do this in practice using Julia.</p>
<p>If you want to learn more about LR models in Julia, check out this video tutorial: </p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/n03pSsA7NtQ" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<h2 id="heading-time-to-talk-decision-trees">Time to Talk Decision Trees 🌴</h2>
<p>We now know the main constrains of linear models: the relationship must be linear. But what about Decision Trees (DTs)? What is the main use case for them and what are the limitations? </p>
<p>At their core, DTs allow us to model the outcome of different potential events or situations. For example, you can make a DT for the outcome of flipping a coin or some other event. The basic structure looks like the following image:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/08/tree.png" alt="Basic tree structure" width="600" height="400" loading="lazy">
<em>Decision tree. Image by Author</em></p>
<p>Here we can see we start with some initial condition, and depending on the outcome of that situation, we go into any three possible nodes. The outer nodes have another nested condition associated with them but the inner one is a final state. </p>
<p>One of the best things about DTs is that for our housing data example, we can build a tree that might say something like: "If the square footage is between 1000-2000 feet, then the value is $400,000". This is an oversimplification but you can use DTs for modeling regression examples as well as classification problems. </p>
<p>The reason this if/then structure is so important is that the tree itself actually becomes quite readable by a human. This is contrasted with ML models in the Deep Learning space, for example, where they are black boxes that we cannot usually understand. The explainability of DTs is one of the core reasons people use them in practice.</p>
<h2 id="heading-decision-trees-vs-linear-regression">Decision Tree's Vs Linear Regression</h2>
<p>Another important thing to point out about DTs, which is the key difference from linear models, is that DTs are commonly used to model non-linear relationships. </p>
<p>When dealing with problems where there are a lot of variables in play, decision trees are also very helpful at quickly identifying what the important variables are.</p>
<p>Now that we know the basics of decision trees (and if you still want to learn more about the more specific tree vernacular and such, check out <a target="_blank" href="https://www.mastersindatascience.org/learning/machine-learning-algorithms/decision-tree/">this article</a>), let's dive into some code examples and set up a tree. </p>
<h2 id="heading-decision-trees-in-action">Decision Tree's in Action 🌲🪓</h2>
<p>For this example, we will be using the <a target="_blank" href="https://archive.ics.uci.edu/ml/datasets/iris">Iris dataset</a> with the <a target="_blank" href="https://github.com/JuliaAI/DecisionTree.jl">DecisionTree.jl package</a>. We start off by loading in the dataset as follows:</p>
<pre><code class="lang-julia"><span class="hljs-keyword">using</span> DecisionTree

features, labels = load_data(<span class="hljs-string">"iris"</span>)
</code></pre>
<p>By default, the <code>load_data</code> function creates the <code>features</code> and <code>labels</code> variables to be of type <code>any</code> which is very computationally expensive. We can reduce this burden by converting the types explicitly to float and string, respectively:</p>
<pre><code class="lang-julia">features = float.(features)
labels   = string.(labels)
</code></pre>
<p>Next, we can call the <code>build_tree</code> function and pass in our labels and features:</p>
<pre><code class="lang-julia">model = build_tree(labels, features)
</code></pre>
<p>Now that we have our tree, we need to prune it to get some results. </p>
<pre><code class="lang-julia">model = prune_tree(model, <span class="hljs-number">0.9</span>)

<span class="hljs-comment"># print of the tree with a depth of 6 nodes (optional)</span>
print_tree(model, <span class="hljs-number">6</span>)
</code></pre>
<p>When we prune the tree, we can set the purity level to 90% in this case which means that we merge leaves that have 90% purity. </p>
<p>Purity in DTs is the idea that there is some data in each decision that falls into the wrong place. For example, we might only have 70% of the data we would expect to fall into a certain class fall into the class, which would give us 70% purity. </p>
<p>The <code>print_tree</code> function from above is a nice way of seeing what we have made so far:</p>
<pre><code class="lang-julia">Feature <span class="hljs-number">4</span> &lt; <span class="hljs-number">0.8</span> ?
├─ Iris-setosa : <span class="hljs-number">50</span>/<span class="hljs-number">50</span>
└─ Feature <span class="hljs-number">4</span> &lt; <span class="hljs-number">1.75</span> ?
    ├─ Feature <span class="hljs-number">3</span> &lt; <span class="hljs-number">4.95</span> ?
        ├─ Iris-versicolor : <span class="hljs-number">47</span>/<span class="hljs-number">48</span>
        └─ Feature <span class="hljs-number">4</span> &lt; <span class="hljs-number">1.55</span> ?
            ├─ Iris-virginica : <span class="hljs-number">3</span>/<span class="hljs-number">3</span>
            └─ Feature <span class="hljs-number">3</span> &lt; <span class="hljs-number">5.45</span> ?
                ├─ Iris-versicolor : <span class="hljs-number">2</span>/<span class="hljs-number">2</span>
                └─ Iris-virginica : <span class="hljs-number">1</span>/<span class="hljs-number">1</span>
    └─ Feature <span class="hljs-number">3</span> &lt; <span class="hljs-number">4.85</span> ?
        ├─ Feature <span class="hljs-number">1</span> &lt; <span class="hljs-number">5.95</span> ?
            ├─ Iris-versicolor : <span class="hljs-number">1</span>/<span class="hljs-number">1</span>
            └─ Iris-virginica : <span class="hljs-number">2</span>/<span class="hljs-number">2</span>
        └─ Iris-virginica : <span class="hljs-number">43</span>/<span class="hljs-number">43</span>
</code></pre>
<p>This visualization shows us exactly what the tree is doing and how it is making these classification buckets. There are also more visualization tools like D3Trees.jl which would make this more interactive to view. </p>
<p>Now that we have the model, we can test it on a single data point:</p>
<pre><code class="lang-julia">julia&gt; apply_tree(model, [<span class="hljs-number">5.9</span>,<span class="hljs-number">3.0</span>,<span class="hljs-number">5.1</span>,<span class="hljs-number">1.9</span>])
<span class="hljs-string">"Iris-virginica"</span>
</code></pre>
<p>Or, we can make predictions on all of our data and look at the confusion matrix:</p>
<pre><code class="lang-julia">preds = apply_tree(model, features)

DecisionTree.confusion_matrix(labels, preds)

Classes:  [<span class="hljs-string">"Iris-setosa"</span>, <span class="hljs-string">"Iris-versicolor"</span>, <span class="hljs-string">"Iris-virginica"</span>]
<span class="hljs-built_in">Matrix</span>:   <span class="hljs-number">3</span>×<span class="hljs-number">3</span> <span class="hljs-built_in">Matrix</span>{<span class="hljs-built_in">Int64</span>}:
 <span class="hljs-number">50</span>   <span class="hljs-number">0</span>   <span class="hljs-number">0</span>
  <span class="hljs-number">0</span>  <span class="hljs-number">50</span>   <span class="hljs-number">0</span>
  <span class="hljs-number">0</span>   <span class="hljs-number">1</span>  <span class="hljs-number">49</span>

Accuracy: <span class="hljs-number">0.9933333333333333</span>
Kappa:    <span class="hljs-number">0.9899999999999998</span>
<span class="hljs-number">3</span>×<span class="hljs-number">3</span> <span class="hljs-built_in">Matrix</span>{<span class="hljs-built_in">Int64</span>}:
 <span class="hljs-number">50</span>   <span class="hljs-number">0</span>   <span class="hljs-number">0</span>
  <span class="hljs-number">0</span>  <span class="hljs-number">50</span>   <span class="hljs-number">0</span>
  <span class="hljs-number">0</span>   <span class="hljs-number">1</span>  <span class="hljs-number">49</span>
</code></pre>
<p>As you can see, the accuracy of this model is actually quite good given the limited dataset and short training time. </p>
<p>This example should be enough to get you going on your DT journey, but if you need more help, check out this awesome video: </p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/XTApO31m3Xs" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<h2 id="heading-wrapping-up">Wrapping up 👋</h2>
<p>This post was a lightning-fast tour of some of the differences between Decision Trees and Linear Models as well as how to program them in Julia. </p>
<p>I hope you walk away from this with confidence that you can go and apply these tools in your own workflows! </p>
<p>If you enjoyed the article, please consider sharing it and you are always welcome to reach out to me on Twitter: <a target="_blank" href="https://twitter.com/OfficialLoganK">https://twitter.com/OfficialLoganK</a></p>
<p>Happy programming! </p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Build Your First Web App in Julia with Genie.jl 🧞‍♂️ ]]>
                </title>
                <description>
                    <![CDATA[ By Logan Kilpatrick Julia is a high-level, dynamic, and open-source programming language. It's designed to be as easy to use as Python while remaining as performant as C or C++.  Many early use cases for Julia were in the scientific domains where mas... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-build-web-apps-in-julia/</link>
                <guid isPermaLink="false">66d460133bc3ab877dae220a</guid>
                
                    <category>
                        <![CDATA[ Julialang ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Julia ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Applications ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Tue, 01 Feb 2022 21:33:45 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/01/Web-applications-in-Julia.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Logan Kilpatrick</p>
<p>Julia is a high-level, dynamic, and open-source programming language. It's designed to be as easy to use as Python while remaining as performant as C or C++. </p>
<p>Many early use cases for Julia were in the scientific domains where massive computational processing was and still is required. But as the language has continued to grow, more and more use cases are gaining steam (hint: web development). </p>
<p>If you are totally new to Julia and want to get a handle on the syntax before you dive into creating your first web application, <a target="_blank" href="https://www.freecodecamp.org/news/learn-julia-programming-language/">check out this article on freeCodeCamp</a>.</p>
<p>It goes over the basics, how to install Julia, steps to install packages, and much more! </p>
<p>We will focus this tutorial on all the necessary steps to build your first web application in Julia from the ground up. So let's begin by checking out the Genie website: <a target="_blank" href="https://genieframework.com">https://genieframework.com</a>.</p>
<h2 id="heading-what-is-geniejl">What is Genie.jl? 🧐</h2>
<p>Genie is a modern and highly productive web framework written in Julia. In the project's own words:</p>
<blockquote>
<p>Genie is a full-stack web framework that provides a streamlined and efficient workflow for developing modern web applications. It builds on Julia's strengths (high-level, high-performance, dynamic, JIT-compiled), exposing a rich API and a powerful toolset for productive web development.</p>
</blockquote>
<p>Genie is very similar to the <a target="_blank" href="https://www.djangoproject.com">Django Project</a> in that Genie is more than a single framework. Instead, it is an entire ecosystem with extensions and the like. </p>
<p>But why do we need Genie? The simple answer is that as Julia continues to grow in popularity, more and more developers are looking to leverage Julia across their entire stack. Genie provides the ability to deploy websites with Julia code running on the server-side so you can do things like deploy machine learning models as part of your Genie app.</p>
<p>Before we dive into getting started with Genie, you might want to check out a live deployed Genie app to get a sense of what is possible: <a target="_blank" href="https://pkgs.genieframework.com">https://pkgs.genieframework.com</a>. </p>
<p>This project is a community resource where you can query the number of package downloads during a certain time frame for a specific package. Type in "genie" to see the number of daily downloads.</p>
<p>You might also be interested in learning more about other GUI and web development frameworks in Julia. To learn more broadly about the ecosystem, <a target="_blank" href="https://towardsdatascience.com/6-julia-frameworks-to-create-desktop-guis-and-web-apps-9ae1a941f115">check out this article</a>.</p>
<h2 id="heading-how-to-install-genie">How to Install Genie ⤵️</h2>
<p>To get Genie installed, all we need to do is open the Julia REPL and type <code>] add Genie</code> . This will take care of everything you need. If everything works, you should be able to do:</p>
<pre><code class="lang-julia">julia&gt; <span class="hljs-keyword">using</span> Genie
</code></pre>
<p>without any issues. You are now all set to begin trying out Genie.</p>
<h2 id="heading-how-to-map-urls-to-julia-functions">How to Map URLs to Julia Functions 🗺</h2>
<p>A core part of the Genie framework is the idea of a router. Routers take the user action of visiting a specific URL and associate it with a Julia function being called.</p>
<p>Let's look at a simple example of this. In the REPL, type the following:</p>
<pre><code class="lang-julia">julia&gt; <span class="hljs-keyword">using</span> Genie, Genie.Router

julia&gt; route(<span class="hljs-string">"/hello"</span>) <span class="hljs-keyword">do</span>
           <span class="hljs-string">"Hello freeCodeCamp"</span>
       <span class="hljs-keyword">end</span>
[GET] /hello =&gt; <span class="hljs-comment">#5 | :get_hello</span>
</code></pre>
<p>In this example, we defined the "/hello" URL to return the text "Hello freeCodeCamp". We can verify that this works by starting the server:</p>
<pre><code class="lang-julia">julia&gt; up() <span class="hljs-comment"># start server</span>
┌ Info: 
└ Web Server starting at http://<span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>:<span class="hljs-number">8000</span> 
Genie.AppServer.ServersCollection(<span class="hljs-built_in">Task</span> (runnable) @<span class="hljs-number">0x000000011c5c5bb0</span>, <span class="hljs-literal">nothing</span>)
</code></pre>
<p>Now that the server is up and running, we can visit <a target="_blank" href="http://127.0.0.1:8000"><code>http://127.0.0.1:8000</code></a> in our browser. You will notice we get a 404 page, which is expected since the only route we defined was "/hello". So let's add that to the URL and see what we get:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/01/Screen-Shot-2022-01-29-at-8.25.53-AM.png" alt="Browser window showing nothing but the text &quot;Hello freeCodeCamp&quot;" width="600" height="400" loading="lazy"></p>
<p>And there we go! Our first step towards building a fully functional web application is complete. We can also confirm that the page is loading correctly by checking the REPL which shows this:</p>
<pre><code class="lang-julia">julia&gt; ┌ Error: GET / <span class="hljs-number">404</span>
└ @ Genie.Router ~/.julia/packages/Genie/UxbVJ/src/Router.jl:<span class="hljs-number">163</span>
┌ Error: GET /favicon.ico <span class="hljs-number">404</span>
└ @ Genie.Router ~/.julia/packages/Genie/UxbVJ/src/Router.jl:<span class="hljs-number">163</span>
[ Info: GET /hello <span class="hljs-number">200</span>
</code></pre>
<p>We see the first attempt where the result was a 404 and on the 2nd attempt where we successfully got the response (the 200 message means everything is okay).</p>
<p>Now that we have a basic example working, let's now try and build on this with some more depth. </p>
<p>To do this, we will create a new file. I will be using VS Code but you are welcome to use any IDE you find useful. Before we look at the next piece of code, we need to make sure we shut down the server by typing <code>down()</code> into the REPL. </p>
<p>Okay, onto the next example:</p>
<pre><code class="lang-julia"><span class="hljs-keyword">using</span> Genie, Genie.Router
<span class="hljs-keyword">using</span> Genie.Renderer, Genie.Renderer.Html, Genie.Renderer.Json

route(<span class="hljs-string">"/"</span>) <span class="hljs-keyword">do</span>
    html(<span class="hljs-string">"Hey freeCodeCamp"</span>)
<span class="hljs-keyword">end</span>

route(<span class="hljs-string">"/hello.html"</span>) <span class="hljs-keyword">do</span>
  html(<span class="hljs-string">"Hello freeCodeCamp (in html)"</span>)
<span class="hljs-keyword">end</span>

route(<span class="hljs-string">"/hello.json"</span>) <span class="hljs-keyword">do</span>
  json(<span class="hljs-string">"Hi freeCodeCamp (in json)"</span>)
<span class="hljs-keyword">end</span>

route(<span class="hljs-string">"/hello.txt"</span>) <span class="hljs-keyword">do</span>
   respond(<span class="hljs-string">"Hiya freeCodeCamp (in txt format)"</span>, :text)
<span class="hljs-keyword">end</span>

<span class="hljs-comment"># Launch the server on a specific port, 8002</span>
<span class="hljs-comment"># Run the task asynchronously</span>
up(<span class="hljs-number">8002</span>, async = <span class="hljs-literal">true</span>)
</code></pre>
<p>A lot is going on in this example, so let's walk through what is taking place. </p>
<p>We start by loading in the packages we want. Then, we define 4 different routes. The first one is the index route. So when the user visits <a target="_blank" href="http://127.0.0.1:8002"><code>http://127.0.0.1:8002</code></a> they will see "Hey freeCodeCamp". The routes after the index highlight that each route can give a custom output. In some cases, it can be HTML, in others, it could be JSON or plain text. </p>
<p>The last line of this example showcases the server launching code. As the comment states, we can set the specific port number and choose if we want the routes to run asynchronously or not. We have now successfully created our first <a target="_blank" href="https://genieframework.com/docs/tutorials/Getting-Started.html#developingasimplegeniescript">Genie Script</a>! </p>
<h2 id="heading-how-to-create-a-basic-web-service">How to Create a Basic Web Service 🕸</h2>
<p>Now that we have gotten our hands dirty with the basics, we will now begin to get closer to building a fully-fledged web application. </p>
<p>Before we go all the way there, we are going to take the first step which is creating a basic web service. To do so, we will go into the REPL and switch our current directory to one which is easily accessible. I will use my desktop in this tutorial:</p>
<pre><code class="lang-julia">shell&gt; cd Desktop
/Users/logankilpatrick/Desktop
</code></pre>
<p>To enter shell mode which is shown above, simply type a ";" into the REPL. Now that we have our active directory set to the desktop in my case, we will use the handy generator function to create the service:</p>
<pre><code class="lang-julia">julia&gt; Genie.newapp_webservice(<span class="hljs-string">"freeCodeCampApp"</span>)

[ Info: Done! New app created at /Users/logankilpatrick/Desktop/freeCodeCampApp
[ Info: Changing active directory to /Users/logankilpatrick/Desktop/freeCodeCampApp
    /var/folders/tc/<span class="hljs-number">519</span>vfm453fj_x5bmd8pwx9480000gn/T/jl_bO1R8h/FreeCodeCampApp/Project.toml
[ Info: Project.toml has been generated
[ Info: Installing app dependencies
...
</code></pre>
<p>The <code>newapp_webservice</code> is a very helpful function that automatically creates all the pieces we need for our first web service. Now that we have a project created, we need to open it up in an IDE (in my case, VS Code). You should see the following if you open up the correct folder:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/01/Screen-Shot-2022-01-30-at-7.39.23-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>There are a lot of files created for us automatically. The main one we will look at is <code>routes.jl</code> which is used to create routes as we did in the section above. </p>
<p>The function we called to generate these folders automatically starts the server, so let's take a quick look at the existing landing page by visiting <a target="_blank" href="http://127.0.0.1:8000">http://127.0.0.1:8000</a>:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/01/Screen-Shot-2022-01-30-at-7.51.16-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>As you might notice, my page looks a little different than yours might because I went in and edited the <code>welcome.html</code> page found in the public folder. </p>
<p>As you can see in <code>routes.jl</code>, when the user visits the main URL <code>/</code>, we route them to the welcome page. We can add in additional routes as we did in the section above and expand this. You are welcome to pause here and play around. We already have a pretty robust website setup.</p>
<p>If you take a peek into some of the other folders like <code>config/env</code>, you will see details around setting the port, host URL, and other relevant parameters. Again, feel free to play around there but we will not go into all the detail of those files in this tutorial. </p>
<p>Before we dive into the next topic, let's take a look at a few more of the files generated for our basic web service:</p>
<ul>
<li>The public folder has all of the front end files (HTML and CSS)</li>
<li>The <code>src</code> folder has the entry point to the web service (in my case <code>freeCodeCampApp.jl</code>)</li>
<li>bin contains some additional dependencies we will again ignore</li>
<li>Manifest.toml and Project.toml are the key Julia files that allow us to maintain our Julia dependencies. When you created the web service, the script automatically activated your current project environment (which is the app we just created). You can verify this by typing "]" into the REPL which will show the active space in blue:</li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/01/Screen-Shot-2022-01-30-at-7.59.49-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>This just means that if we try to add a package, it will add it to the project and manifest file specifically for this project, instead of the globally shared one.</p>
<h2 id="heading-how-to-create-a-fully-functioning-web-app-with-a-database">How to Create a Fully Functioning Web App With a Database 💽</h2>
<p>Now that we have explored the basics, we are going to dive into a full-on web app. Again, Genie provides some nice functions to get us started. Before we create it, we will need to navigate back to the desktop:</p>
<pre><code class="lang-julia">shell&gt; pwd
/Users/logankilpatrick/Desktop/freeCodeCampApp

shell&gt; cd ..
/Users/logankilpatrick/Desktop

shell&gt;
</code></pre>
<p>Remember, you can type <code>;</code> to enter the shell mode and backspace to exit the shell mode. Now, let's create the app:</p>
<pre><code class="lang-julia">julia&gt; Genie.newapp_mvc(Genie.newapp_mvc(<span class="hljs-string">"freeCodeCampMVC"</span>))
   Resolving package versions...
   ...
</code></pre>
<p>You will be prompted to choose a database backend. For this example, we will use SQLite:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/01/Screen-Shot-2022-01-30-at-8.08.31-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>If you want to use a different database backend, feel free to do so as well. But note that you will need to create the database file automatically. Genie only creates an SQLite file for you. </p>
<p>We now have a MVC app created. But you might be asking yourself, what is an MVC? </p>
<p>The Model-View-Controller paradigm is very common across application development. In the interest of not getting into the weeds on it, I will <a target="_blank" href="https://www.freecodecamp.org/news/mvc-architecture-what-is-a-model-view-controller-framework/">refer you to this post</a> where you can read about the details. From our perspective as developers, there is not much impact. </p>
<p>Just like we did when we created the last project, we need to open it in the IDE again:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/02/Screen-Shot-2022-02-01-at-6.44.21-AM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Again, we will see much of the same stuff as before with the new addition of the <code>app</code> folder which will contain a lot of critical code. We can see what the new project looks like by typing:</p>
<pre><code class="lang-julia">julia&gt; loadapp()

julia&gt; up()
</code></pre>
<p>and then navigating too: <a target="_blank" href="http://127.0.0.1:8000">http://127.0.0.1:8000</a>.</p>
<p>Next up, we will need to connect our database to the web app we created. To do this, head to <code>db/connection.yml</code> and edit the following section:</p>
<pre><code class="lang-yml"><span class="hljs-attr">env:</span> <span class="hljs-string">ENV["GENIE_ENV"]</span>

<span class="hljs-attr">dev:</span>
  <span class="hljs-attr">adapter:</span> <span class="hljs-string">SQLite</span>
  <span class="hljs-attr">database:</span> <span class="hljs-string">db/freeCodeCamp_courses.sqlite</span>
</code></pre>
<p>You can leave the rest of the fields blank for now. Then, we need to run:</p>
<pre><code class="lang-julia">julia&gt; include(joinpath(<span class="hljs-string">"config"</span>, <span class="hljs-string">"initializers"</span>, <span class="hljs-string">"searchlight.jl"</span>))
</code></pre>
<p>which will load the database configuration. Next up, we will continue to configure the database such that we can save data from our app into persistent storage.</p>
<p>We begin this process by creating a new resource:</p>
<pre><code class="lang-julia">julia&gt; Genie.newresource(<span class="hljs-string">"course"</span>)
</code></pre>
<p>Once we have defined a resource, the next step is to go and edit the database migrations table which can be found at <code>db/migrations/2022020115190055_create_table_courses.jl</code> in my case. </p>
<p>By default, the table is already populated with some placeholder text based on the last few commands we ran. It should look something like this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/02/Screen-Shot-2022-02-01-at-7.22.35-AM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>We will edit the file to match the specific scheme we want. This will be entirely dependent on the application itself. Since I am making courses on this site, I will enter all of the course details as follows:</p>
<pre><code class="lang-julia"><span class="hljs-keyword">module</span> CreateTableCourses

<span class="hljs-keyword">import</span> SearchLight.Migrations: create_table, column, columns, pk, add_index, drop_table, add_indices

<span class="hljs-keyword">function</span> up()
  create_table(:courses) <span class="hljs-keyword">do</span>
    [
      pk()
      column(:title, :string, limit = <span class="hljs-number">200</span>)
      column(:authors, :string, limit = <span class="hljs-number">250</span>)
      column(:year, :integer, limit = <span class="hljs-number">4</span>)
      column(:rating, :string, limit = <span class="hljs-number">10</span>)
      column(:categories, :string, limit = <span class="hljs-number">100</span>)
      column(:description, :string, limit = <span class="hljs-number">1_000</span>)
      column(:cost, :float, limit = <span class="hljs-number">1000</span>)
    ]
  <span class="hljs-keyword">end</span>

  add_index(:courses, :title)
  add_index(:courses, :authors)
  add_index(:courses, :categories)
  add_index(:courses, :description)

<span class="hljs-keyword">end</span>

<span class="hljs-keyword">function</span> down()
  drop_table(:courses)
<span class="hljs-keyword">end</span>

<span class="hljs-keyword">end</span>
</code></pre>
<p>Again, these are arbitrary and can be whatever you want them to be. </p>
<p>It is worth noting that adding the index is optional. The reason you would add it is that it speeds up the queries, but there are other tradeoffs and you can't actually load all the columns as indexes. You can read more about some of these tradeoffs <a target="_blank" href="https://stackoverflow.com/questions/5447987/why-cant-i-simply-add-an-index-that-includes-all-columns/5448055#5448055">here</a> and <a target="_blank" href="https://stackoverflow.com/questions/107132/what-columns-generally-make-good-indexes">here</a>.</p>
<p>Now that we have the database table updated, we need to propagate these updates. To do so, we will use <code>SearchLight.jl</code> which functions as our app's migration system:</p>
<pre><code class="lang-julia">julia&gt; <span class="hljs-keyword">using</span> SearchLight

julia&gt; SearchLight.Migration.create_migrations_table()
┌ Info: <span class="hljs-number">2022</span>-<span class="hljs-number">02</span>-<span class="hljs-number">01</span> <span class="hljs-number">07</span>:<span class="hljs-number">37</span>:<span class="hljs-number">11</span> CREATE TABLE <span class="hljs-string">`schema_migrations`</span> (
│       <span class="hljs-string">`version`</span> varchar(<span class="hljs-number">30</span>) NOT NULL DEFAULT '',
│       PRIMARY KEY (<span class="hljs-string">`version`</span>)
└     )
[ Info: <span class="hljs-number">2022</span>-<span class="hljs-number">02</span>-<span class="hljs-number">01</span> <span class="hljs-number">07</span>:<span class="hljs-number">37</span>:<span class="hljs-number">11</span> Created table schema_migrations

julia&gt; SearchLight.Migration.status()
[ Info: <span class="hljs-number">2022</span>-<span class="hljs-number">02</span>-<span class="hljs-number">01</span> <span class="hljs-number">07</span>:<span class="hljs-number">37</span>:<span class="hljs-number">20</span> SELECT version FROM schema_migrations ORDER BY version DESC
|   | <span class="hljs-built_in">Module</span> name &amp; status                     |
|   | File name                                |
|---|------------------------------------------|
|   |                 CreateTableCourses: DOWN |
| <span class="hljs-number">1</span> | <span class="hljs-number">2022020115190055_</span>create_table_courses.jl |

julia&gt; SearchLight.Migration.last_up()
[ Info: <span class="hljs-number">2022</span>-<span class="hljs-number">02</span>-<span class="hljs-number">01</span> <span class="hljs-number">07</span>:<span class="hljs-number">37</span>:<span class="hljs-number">29</span> SELECT version FROM schema_migrations ORDER BY version DESC
[ Info: <span class="hljs-number">2022</span>-<span class="hljs-number">02</span>-<span class="hljs-number">01</span> <span class="hljs-number">07</span>:<span class="hljs-number">37</span>:<span class="hljs-number">29</span> CREATE TABLE courses (id INTEGER PRIMARY KEY , title TEXT  , authors TEXT  , year INTEGER (<span class="hljs-number">4</span>) , rating TEXT  , categories TEXT  , description TEXT  , cost FLOAT (<span class="hljs-number">1000</span>) )
[ Info: <span class="hljs-number">2022</span>-<span class="hljs-number">02</span>-<span class="hljs-number">01</span> <span class="hljs-number">07</span>:<span class="hljs-number">37</span>:<span class="hljs-number">29</span> CREATE  INDEX courses__idx_title ON courses (title)
[ Info: <span class="hljs-number">2022</span>-<span class="hljs-number">02</span>-<span class="hljs-number">01</span> <span class="hljs-number">07</span>:<span class="hljs-number">37</span>:<span class="hljs-number">29</span> CREATE  INDEX courses__idx_authors ON courses (authors)
[ Info: <span class="hljs-number">2022</span>-<span class="hljs-number">02</span>-<span class="hljs-number">01</span> <span class="hljs-number">07</span>:<span class="hljs-number">37</span>:<span class="hljs-number">29</span> CREATE  INDEX courses__idx_categories ON courses (categories)
[ Info: <span class="hljs-number">2022</span>-<span class="hljs-number">02</span>-<span class="hljs-number">01</span> <span class="hljs-number">07</span>:<span class="hljs-number">37</span>:<span class="hljs-number">29</span> CREATE  INDEX courses__idx_description ON courses (description)
[ Info: <span class="hljs-number">2022</span>-<span class="hljs-number">02</span>-<span class="hljs-number">01</span> <span class="hljs-number">07</span>:<span class="hljs-number">37</span>:<span class="hljs-number">29</span> INSERT INTO schema_migrations VALUES ('<span class="hljs-number">2022020115190055</span>')
[ Info: <span class="hljs-number">2022</span>-<span class="hljs-number">02</span>-<span class="hljs-number">01</span> <span class="hljs-number">07</span>:<span class="hljs-number">37</span>:<span class="hljs-number">29</span> Executed migration CreateTableCourses up
</code></pre>
<p>We have now successfully completed the migrations. If you were to make a change to the schema, you would need to re-run the commands above for those database changes to take effect. </p>
<p>The last step in this process is to define our model. This will allow us to create objects in Julia code and then save them to the database we just defined. We need to navigate to <code>app/resources/courses/Courses.jl</code> or the equivalent path to make these final updates: </p>
<pre><code class="lang-julia"><span class="hljs-keyword">module</span> Courses

<span class="hljs-keyword">import</span> SearchLight: AbstractModel, DbId
<span class="hljs-keyword">import</span> Base: <span class="hljs-meta">@kwdef</span>

<span class="hljs-keyword">export</span> Course

<span class="hljs-meta">@kwdef</span> <span class="hljs-keyword">mutable struct</span> Course &lt;: AbstractModel
  id::DbId = DbId()
  title::<span class="hljs-built_in">String</span> = <span class="hljs-string">""</span>
  authors::<span class="hljs-built_in">String</span> = <span class="hljs-string">""</span>
  year::<span class="hljs-built_in">Int</span> = <span class="hljs-number">0</span>
  rating::<span class="hljs-built_in">String</span> = <span class="hljs-string">""</span>
  categories::<span class="hljs-built_in">String</span> = <span class="hljs-string">""</span>
  description::<span class="hljs-built_in">String</span> = <span class="hljs-string">""</span>
  cost::<span class="hljs-built_in">Float64</span> = <span class="hljs-number">0.0</span>
<span class="hljs-keyword">end</span>

<span class="hljs-keyword">end</span>
</code></pre>
<p>Again, this should be the same as the content you previously defined. To make sure this worked, we can do:</p>
<pre><code class="lang-julia">julia&gt; <span class="hljs-keyword">using</span> Courses
[ Info: <span class="hljs-number">2022</span>-<span class="hljs-number">02</span>-<span class="hljs-number">01</span> <span class="hljs-number">07</span>:<span class="hljs-number">43</span>:<span class="hljs-number">51</span> Precompiling Courses [top-level]
</code></pre>
<p>and then try creating a course via:</p>
<pre><code class="lang-julia">
julia&gt; c = Course(title = <span class="hljs-string">"Web dev with Genie.jl"</span>, authors=<span class="hljs-string">"Logan Kilpatrick"</span>)
Course
| KEY                 | VALUE                 |
|---------------------|-----------------------|
| authors::<span class="hljs-built_in">String</span>     | Logan Kilpatrick      |
| categories::<span class="hljs-built_in">String</span>  |                       |
| cost::<span class="hljs-built_in">Float64</span>       | <span class="hljs-number">0.0</span>                   |
| description::<span class="hljs-built_in">String</span> |                       |
| id::DbId            | NULL                  |
| rating::<span class="hljs-built_in">String</span>      |                       |
| title::<span class="hljs-built_in">String</span>       | Web dev with Genie.jl |
| year::<span class="hljs-built_in">Int64</span>         | <span class="hljs-number">0</span>                     |
</code></pre>
<p>We have successfully created our first object! But it is not saved to the database right away. We can verify this by doing:</p>
<pre><code class="lang-julia">julia&gt; ispersisted(c)
<span class="hljs-literal">false</span>
</code></pre>
<p>so we need to run:</p>
<pre><code class="lang-julia">julia&gt; save(c)
[ Info: <span class="hljs-number">2022</span>-<span class="hljs-number">02</span>-<span class="hljs-number">01</span> <span class="hljs-number">07</span>:<span class="hljs-number">47</span>:<span class="hljs-number">04</span> INSERT  INTO courses (<span class="hljs-string">"title"</span>, <span class="hljs-string">"authors"</span>, <span class="hljs-string">"year"</span>, <span class="hljs-string">"rating"</span>, <span class="hljs-string">"categories"</span>, <span class="hljs-string">"description"</span>, <span class="hljs-string">"cost"</span>) VALUES ('Web dev with Genie.jl', 'Logan Kilpatrick', <span class="hljs-number">0</span>, '', '', '', <span class="hljs-number">0.0</span>) 
[ Info: <span class="hljs-number">2022</span>-<span class="hljs-number">02</span>-<span class="hljs-number">01</span> <span class="hljs-number">07</span>:<span class="hljs-number">47</span>:<span class="hljs-number">04</span> ; SELECT CASE WHEN last_insert_rowid() = <span class="hljs-number">0</span> THEN -<span class="hljs-number">1</span> ELSE last_insert_rowid() END AS LAST_INSERT_ID
<span class="hljs-literal">true</span>
</code></pre>
<p>and now the course is saved! But to really test this out, we need the user to be able to create a course. Let's head back to <code>routes.jl</code> and enable that:</p>
<pre><code class="lang-julia"><span class="hljs-keyword">using</span> Genie, Genie.Router, Genie.Renderer.Html, Genie.Requests
<span class="hljs-keyword">using</span> Courses

form = <span class="hljs-string">"""
&lt;form action="/" method="POST" enctype="multipart/form-data"&gt;
  &lt;input type="text" name="name" value="" placeholder="What's the course name?" /&gt;
  &lt;input type="text" name="author" value="" placeholder="Who is the course author?" /&gt;

  &lt;input type="submit" value="Submit" /&gt;
&lt;/form&gt;
"""</span>

route(<span class="hljs-string">"/"</span>) <span class="hljs-keyword">do</span>
  html(form)
<span class="hljs-keyword">end</span>

route(<span class="hljs-string">"/"</span>, method = POST) <span class="hljs-keyword">do</span>
  c = Course(title=postpayload(:name, <span class="hljs-string">"Placeholder"</span>), authors=postpayload(:author, <span class="hljs-string">"Placeholder"</span>))
  save(c)
  <span class="hljs-string">"Course titled <span class="hljs-subst">$(c.title)</span> created successfully!"</span>
<span class="hljs-keyword">end</span>
</code></pre>
<p>We started by defining a simple HTML form (nothing new or exciting here), then, we made it so the default route <code>/</code> renders the HTML form. Lastly, we create another route for the <code>/</code> URL, but specifically for the POST method. Inside that route, we create a new course by pulling the info we want from the form out of the payload via <code>postpayload</code>. </p>
<p>You can try this by navigating back to: <a target="_blank" href="http://127.0.0.1:8000">http://127.0.0.1:8000</a></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/02/Screen-Shot-2022-02-01-at-8.11.38-AM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>You can try and enter some of the details and then press submit. To make sure the submissions worked, you can do:</p>
<pre><code class="lang-julia">julia&gt; all(Course)
[ Info: <span class="hljs-number">2022</span>-<span class="hljs-number">02</span>-<span class="hljs-number">01</span> <span class="hljs-number">08</span>:<span class="hljs-number">10</span>:<span class="hljs-number">19</span> SELECT <span class="hljs-string">"courses"</span>.<span class="hljs-string">"id"</span> AS <span class="hljs-string">"courses_id"</span>, <span class="hljs-string">"courses"</span>.<span class="hljs-string">"title"</span> AS <span class="hljs-string">"courses_title"</span>, <span class="hljs-string">"courses"</span>.<span class="hljs-string">"authors"</span> AS <span class="hljs-string">"courses_authors"</span>, <span class="hljs-string">"courses"</span>.<span class="hljs-string">"year"</span> AS <span class="hljs-string">"courses_year"</span>, <span class="hljs-string">"courses"</span>.<span class="hljs-string">"rating"</span> AS <span class="hljs-string">"courses_rating"</span>, <span class="hljs-string">"courses"</span>.<span class="hljs-string">"categories"</span> AS <span class="hljs-string">"courses_categories"</span>, <span class="hljs-string">"courses"</span>.<span class="hljs-string">"description"</span> AS <span class="hljs-string">"courses_description"</span>, <span class="hljs-string">"courses"</span>.<span class="hljs-string">"cost"</span> AS <span class="hljs-string">"courses_cost"</span> FROM <span class="hljs-string">"courses"</span> ORDER BY courses.id ASC
┌ Warning: <span class="hljs-number">2022</span>-<span class="hljs-number">02</span>-<span class="hljs-number">01</span> <span class="hljs-number">08</span>:<span class="hljs-number">10</span>:<span class="hljs-number">19</span> Unsupported SQLite declared <span class="hljs-keyword">type</span> INTEGER (<span class="hljs-number">4</span>), falling back to <span class="hljs-built_in">Int64</span> <span class="hljs-keyword">type</span>
└ @ SQLite ~/.julia/packages/SQLite/aDggE/src/SQLite.jl:<span class="hljs-number">416</span>
┌ Warning: <span class="hljs-number">2022</span>-<span class="hljs-number">02</span>-<span class="hljs-number">01</span> <span class="hljs-number">08</span>:<span class="hljs-number">10</span>:<span class="hljs-number">19</span> Unsupported SQLite declared <span class="hljs-keyword">type</span> FLOAT (<span class="hljs-number">1000</span>), falling back to <span class="hljs-built_in">Float64</span> <span class="hljs-keyword">type</span>
└ @ SQLite ~/.julia/packages/SQLite/aDggE/src/SQLite.jl:<span class="hljs-number">416</span>
<span class="hljs-number">3</span>-element <span class="hljs-built_in">Vector</span>{Course}:
 Course
| KEY                 | VALUE                 |
|---------------------|-----------------------|
| authors::<span class="hljs-built_in">String</span>     | Logan Kilpatrick      |
| categories::<span class="hljs-built_in">String</span>  |                       |
| cost::<span class="hljs-built_in">Float64</span>       | <span class="hljs-number">0.0</span>                   |
| description::<span class="hljs-built_in">String</span> |                       |
| id::DbId            | <span class="hljs-number">1</span>                     |
| rating::<span class="hljs-built_in">String</span>      |                       |
| title::<span class="hljs-built_in">String</span>       | Web dev with Genie.jl |
| year::<span class="hljs-built_in">Int64</span>         | <span class="hljs-number">0</span>                     |

 Course
| KEY                 | VALUE       |
|---------------------|-------------|
| authors::<span class="hljs-built_in">String</span>     | Logan K     |
| categories::<span class="hljs-built_in">String</span>  |             |
| cost::<span class="hljs-built_in">Float64</span>       | <span class="hljs-number">0.0</span>         |
| description::<span class="hljs-built_in">String</span> |             |
| id::DbId            | <span class="hljs-number">2</span>           |
| rating::<span class="hljs-built_in">String</span>      |             |
| title::<span class="hljs-built_in">String</span>       | Test course |
| year::<span class="hljs-built_in">Int64</span>         | <span class="hljs-number">0</span>           |
</code></pre>
<p>which should show that the entries were saved in the database.</p>
<h2 id="heading-wrapping-up">Wrapping up 🎁</h2>
<p>Wow, that was a lot. We covered a tremendous amount of ground in this single tutorial. </p>
<p>With that said, there is even more to learn about Genie. I highly suggest checking out the <a target="_blank" href="https://genieframework.com/docs/tutorials/Overview.html">docs here</a>, which has lots more tutorials on topics like REST API's, Authentication, and much more. </p>
<h2 id="heading-getting-help-with-geniejl">Getting help with Genie.jl 🚨</h2>
<p>If you run into issues with this tutorial or when using Genie, please post a question on Stack Overflow with the <code>genie.jl</code> and <code>julia</code> tag or on the <a target="_blank" href="https://discourse.julialang.org">Julia Discourse</a>. After that, feel free to tweet the link to the question at me and I will do my best to help: <a target="_blank" href="https://twitter.com/OfficialLoganK">https://twitter.com/OfficialLoganK</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Learn Julia For Beginners – The Future Programming Language of  Data Science and Machine Learning Explained ]]>
                </title>
                <description>
                    <![CDATA[ By Logan Kilpatrick Julia is a high-level, dynamic programming language, designed to give users the speed of C/C++ while remaining as easy to use as Python. This means that developers can solve problems faster and more effectively. Julia is great for... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/learn-julia-programming-language/</link>
                <guid isPermaLink="false">66d4601751f567b42d9f8491</guid>
                
                    <category>
                        <![CDATA[ Data Science ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Julia ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Julialang ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Machine Learning ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 27 Dec 2021 17:13:56 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/12/LearningJuliafreeCodeCamp.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Logan Kilpatrick</p>
<p>Julia is a high-level, dynamic programming language, designed to give users the speed of C/C++ while remaining as easy to use as Python. This means that developers can solve problems faster and more effectively.</p>
<p>Julia is great for computational complex problems. Many early adopters of Julia were concentrated in scientific domains like Chemistry, Biology, and Machine Learning. </p>
<p>This said, Julia is general-purpose language and can be used for tasks like Web Development, Game Development, and more. Many view Julia as the next-generation language for Machine Learning and Data Science, including the CEO of Shopify (among many others):</p>
<div class="embed-wrapper">
        <blockquote class="twitter-tweet">
          <a href="https://twitter.com/tobi/status/1474369669888937992?s=20"></a>
        </blockquote>
        <script defer="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script></div>
<h2 id="heading-how-to-download-the-julia-programming-language">How to Download the Julia Programming Language ⤵️</h2>
<p>There are two main ways to run Julia: via a <code>.jl</code> file in an <a target="_blank" href="https://code.visualstudio.com/docs/languages/julia">IDE like VS Code</a> or command by command in the Julia REPL (Read Evaluate Print Loop). In this guide, we will mainly use the Julia REPL. Before you can use either, you will need to download Julia:</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/t67TGcf4SmM" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<p>or just head to: <a target="_blank" href="https://julialang.org/downloads/">https://julialang.org/downloads/</a></p>
<p>After you have Julia installed, you should be able to launch it and see:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/12/Screen-Shot-2021-12-24-at-5.56.14-AM.png" alt="Image" width="600" height="400" loading="lazy">
<em>Julia 1.7 REPL after install</em></p>
<h2 id="heading-julia-programming-language-basics-for-beginners">Julia Programming Language Basics for Beginners</h2>
<p>Before we can use Julia for all of the exciting things it was built for like Machine Learning or Data Science, we first need to get familiar with the basics of the language. </p>
<p>We will start by going over variables, types, and conditionals. Then, we will talk about loops, functions, and packages. Last, we’ll touch on more advanced concepts like structs and talk about additional learning resources. </p>
<p>This is going to be a whirlwind tour so strap in and get ready! It is also worth noting that this tutorial assumes you have some basic familiarity with programming. If you don't, check out this course on an <a target="_blank" href="https://juliaacademy.com/p/julia-programming-for-nervous-beginners">Intro to Julia for Nervous Beginners</a>.</p>
<h2 id="heading-an-introduction-to-julia-variables-and-types">An Introduction to Julia Variables and Types ⌨️</h2>
<p>In Julia, variables are dynamically typed, meaning that you do not need to specify the variable's type when you create it.</p>
<pre><code class="lang-julia">julia&gt; a = <span class="hljs-number">10</span> <span class="hljs-comment"># Create the variable "a" and assign it the number 10</span>
<span class="hljs-number">10</span>

julia&gt; a + <span class="hljs-number">10</span> <span class="hljs-comment"># Do a basic math operation using "a"</span>
<span class="hljs-number">20</span>
</code></pre>
<p><em>(Note that in code snippets, when you see <code>julia&gt;</code> it means the code is being run in the REPL)</em></p>
<p>Just like we defined a variable above and assigned it an integer (whole number), we can also do something similar for strings and other variable types:</p>
<pre><code class="lang-julia">julia&gt; my_string = <span class="hljs-string">"Hello freeCodeCamp"</span> <span class="hljs-comment"># Define a string variable</span>
<span class="hljs-string">"Hello freeCodeCamp"</span>

julia&gt; balance = <span class="hljs-number">238.19</span> <span class="hljs-comment"># Define a float variable </span>
<span class="hljs-number">238.19</span>
</code></pre>
<p>When creating variables in Julia, the variable name will always go on the left-hand side, and the value will always go on the right-hand side after the equals sign. We can also create new variables based on the values of other variables:</p>
<pre><code class="lang-julia">julia&gt; new_balance = balance + a
<span class="hljs-number">248.19</span>
</code></pre>
<p>Here we can see that the <code>new_balance</code> is now the sum (total) of 238.19 and 10. Note further that the type of <code>new_balance</code> is a float (number with decimal place precision) because when we add a float and int together, we automatically get the type with higher precision, which in this case is a float. We can confirm this by doing:</p>
<pre><code class="lang-julia">julia&gt; typeof(new_balance)
<span class="hljs-built_in">Float64</span>
</code></pre>
<p>Due to the nature of dynamic typing, variables in Julia can also change type. This means that at one point, <code>holder_balance</code> could be a float, and then later on it could be a string:</p>
<pre><code class="lang-julia">julia&gt; holder_balance = <span class="hljs-number">100.34</span>
<span class="hljs-number">100.34</span>

julia&gt; holder_balance = <span class="hljs-string">"The Type has changed"</span>
<span class="hljs-string">"The Type has changed"</span>

julia&gt; typeof(holder_balance)
<span class="hljs-built_in">String</span>
</code></pre>
<p>You may also be excited to know that variable names in Julia are very flexible, in fact, you can do something like:</p>
<pre><code class="lang-julia">julia&gt; 😀 = <span class="hljs-number">10</span>
<span class="hljs-number">10</span>

julia&gt; 🥲 = -<span class="hljs-number">10</span>
-<span class="hljs-number">10</span>

julia&gt; 😀 + 🥲
<span class="hljs-number">0</span>
</code></pre>
<p>On top of emoji variable names, you can also use any other Unicode variable name which is very helpful when you are trying to represent mathematical ideas. You can access these Unicode variables by doing a <code>\</code> and then typing the name, followed by pressing tab:</p>
<pre><code class="lang-julia">julia&gt; \sigma <span class="hljs-comment"># press tab and it will render the symbol</span>

julia&gt; σ = <span class="hljs-number">10</span> <span class="hljs-comment"># set sigma equal to 10</span>
</code></pre>
<p>Overall, the variable system in Julia is flexible and provides a huge set of features that make writing Julia code easy while still being expressive. If you want to learn more about variables in Julia, check out the Julia documentation: <a target="_blank" href="https://docs.julialang.org/en/v1/manual/variables/">https://docs.julialang.org/en/v1/manual/variables/</a></p>
<h2 id="heading-how-to-write-conditional-statements-in-julia">How to Write Conditional Statements in Julia  🔀</h2>
<p>In programming, you often need to check certain conditions in order to make sure that specific lines of code run. For example, if you write a banking program, you might only want to let someone withdraw money if the amount they are trying to withdraw is less than the amount they have present in their account. </p>
<p>Let us look at a basic example of a conditional statement in Julia:</p>
<pre><code class="lang-julia">julia&gt; bank_balance = <span class="hljs-number">4583.11</span>
<span class="hljs-number">4583.11</span>

julia&gt; withdraw_amount = <span class="hljs-number">250</span>
<span class="hljs-number">250</span>

julia&gt; <span class="hljs-keyword">if</span> withdraw_amount &lt;= bank_balance
           bank_balance -= withdraw_amount
           print(<span class="hljs-string">"Withdrew "</span>, withdraw_amount, <span class="hljs-string">" from your account"</span>)
       <span class="hljs-keyword">end</span>
Withdrew <span class="hljs-number">250</span> from your account
</code></pre>
<p>Let us take a closer look here at some parts of the if statement that might differ from other code you have seen: First, we use no <code>:</code> to denote the end of the line and we also are not required to use <code>()</code> around the statement (though it is encouraged). Next, we don't use <code>{}</code> or the like to denote the end of the conditional, instead, we use the <code>end</code> keyword. </p>
<p>Just like we used the if statement, we can chain it with an <code>else</code> or an <code>elseif</code>:</p>
<pre><code class="lang-julia">julia&gt; withdraw_amount = <span class="hljs-number">4600</span>
<span class="hljs-number">4600</span>

julia&gt; <span class="hljs-keyword">if</span> withdraw_amount &lt;= bank_balance
           bank_balance -= withdraw_amount
           print(<span class="hljs-string">"Withdrew "</span>, withdraw_amount, <span class="hljs-string">" from your account"</span>)
       <span class="hljs-keyword">else</span>
           print(<span class="hljs-string">"Insufficent balance"</span>)
       <span class="hljs-keyword">end</span>
Insufficent balance
</code></pre>
<p>You can read more about control flow and conditional expressions in the Julia documentation: <a target="_blank" href="https://docs.julialang.org/en/v1/manual/control-flow/#man-conditional-evaluation">https://docs.julialang.org/en/v1/manual/control-flow/#man-conditional-evaluation</a></p>
<h2 id="heading-how-to-use-loops-in-julia">How to use Loops in Julia 🔂</h2>
<p>There are two main types of loops in Julia: a for loop and a while loop. As is the same with other languages, the biggest difference is that in a for loop, you are going through a pre-defined number of items whereas, in a while loop, you are iterating until some condition is changed. </p>
<p>Syntactically, the loops in Julia look very similar in structure to the if conditionals we just looked at:</p>
<pre><code class="lang-julia">julia&gt; greeting = [<span class="hljs-string">"Hello"</span>, <span class="hljs-string">"world"</span>, <span class="hljs-string">"and"</span>, <span class="hljs-string">"welcome"</span>, <span class="hljs-string">"to"</span>, <span class="hljs-string">"freeCodeCamp"</span>] <span class="hljs-comment"># define greeting, an array of strings</span>
<span class="hljs-number">6</span>-element <span class="hljs-built_in">Vector</span>{<span class="hljs-built_in">String</span>}:
 <span class="hljs-string">"Hello"</span>
 <span class="hljs-string">"world"</span>
 <span class="hljs-string">"and"</span>
 <span class="hljs-string">"welcome"</span>
 <span class="hljs-string">"to"</span>
 <span class="hljs-string">"freeCodeCamp"</span>

julia&gt; <span class="hljs-keyword">for</span> word <span class="hljs-keyword">in</span> greeting
           print(word, <span class="hljs-string">" "</span>)
       <span class="hljs-keyword">end</span>
Hello world and welcome to freeCodeCamp
</code></pre>
<p>In this example, we first defined a new type: a vector (also called an array). This array is holding a bunch of strings we defined. The behavior is very similar to that of arrays in other languages but it is worth noting that arrays are mutable (meaning you can change the number of items in the array after you create it).</p>
<p>Again, when we look at the structure of the for loop, you can see that we are iterating through the <code>greeting</code> variable. Each time through, we get a new word (in this case) from the array and assign it to a temporary variable <code>word</code> which we then print out. You will notice that the structure of this loop looks similar to the if statement and again uses the <code>end</code> keyword. </p>
<p>Now that we explored for loops, let us switch gears and take a look at a while loop in Julia:</p>
<pre><code class="lang-julia">julia&gt; <span class="hljs-keyword">while</span> user_input != <span class="hljs-string">"End"</span>
           print(<span class="hljs-string">"Enter some input, or End to quit: "</span>)
           user_input = readline() <span class="hljs-comment"># Prompt the user for input</span>
       <span class="hljs-keyword">end</span>
Enter some input, or End to quit: hi
Enter some input, or End to quit: test
Enter some input, or End to quit: no
Enter some input, or End to quit: End
</code></pre>
<p>For this while loop, we set it up so that it will run indefinitely until the user typed the word "End". As you have now seen it a few times, the structure of the loop should start to look familiar. </p>
<p>If you want to see some more examples of loops in Julia, you can check out the Julia Documentation's section on loops: <a target="_blank" href="https://docs.julialang.org/en/v1/manual/control-flow/#man-loops">https://docs.julialang.org/en/v1/manual/control-flow/#man-loops</a></p>
<h2 id="heading-how-to-use-functions-in-julia">How to use Functions in Julia</h2>
<p>Functions are used to create multiple lines of code, chained together, and accessible when you reference a function name. First, let us look at an example of a basic function:</p>
<pre><code class="lang-julia">julia&gt; <span class="hljs-keyword">function</span> greet()
           print(<span class="hljs-string">"Hello new Julia user!"</span>)
       <span class="hljs-keyword">end</span>
greet (generic <span class="hljs-keyword">function</span> with <span class="hljs-number">1</span> method)

julia&gt; greet()
Hello new Julia user!
</code></pre>
<p>Functions can also take arguments, just like in other languages:</p>
<pre><code class="lang-julia">julia&gt; <span class="hljs-keyword">function</span> greetuser(user_name)
           print(<span class="hljs-string">"Hello "</span>, user_name, <span class="hljs-string">", welcome to the Julia Community"</span>)
       <span class="hljs-keyword">end</span>
greetuser (generic <span class="hljs-keyword">function</span> with <span class="hljs-number">1</span> method)

julia&gt; greetuser(<span class="hljs-string">"Logan"</span>)
Hello Logan, welcome to the Julia Community
</code></pre>
<p>In this example, we take in one argument, and then add its value to the print out. But what if we don't get a string?</p>
<pre><code class="lang-julia">julia&gt; greetuser(<span class="hljs-literal">true</span>)
Hello <span class="hljs-literal">true</span>, welcome to the Julia Community
</code></pre>
<p>In this case, since we are just printing, the function continues to work despite not taking in a string anymore and instead of taking a boolean value (true or false). To prevent this from occurring, we can explicitly type the input arguments as follows:</p>
<pre><code class="lang-julia">julia&gt; <span class="hljs-keyword">function</span> greetuser(user_name::<span class="hljs-built_in">String</span>)
           print(<span class="hljs-string">"Hello "</span>, user_name, <span class="hljs-string">", welcome to the Julia Community"</span>)
       <span class="hljs-keyword">end</span>
greetuser (generic <span class="hljs-keyword">function</span> with <span class="hljs-number">2</span> methods)

julia&gt; greetuser(<span class="hljs-string">"Logan"</span>)
Hello Logan, welcome to the Julia Community
</code></pre>
<p>So now the function is defined to take in only a string. Let us test this out to make sure we can only call the function with a string value:</p>
<pre><code class="lang-julia">julia&gt; greetuser(<span class="hljs-literal">true</span>)
Hello <span class="hljs-literal">true</span>, welcome to the Julia Community
</code></pre>
<p>Wait a second, why is this happening? We re-defined the <code>greetuser</code> function, it should not take <code>true</code> anymore. </p>
<p>What we are experiencing here is one of the most powerful underlying features of Julia: Multiple Dispatch. Julia allows us to define functions with the same name and number of arguments but that accept different types. This means we can build either generic or type specific versions of functions which helps immensely with code readability since you don't need to handle every scenario in one function. </p>
<p>We should quickly confirm that we actually defined both functions:</p>
<pre><code class="lang-julia">julia&gt; methods(greetuser)
<span class="hljs-comment"># 2 methods for generic function "greetuser":</span>
[<span class="hljs-number">1</span>] greetuser(user_name::<span class="hljs-built_in">String</span>) <span class="hljs-keyword">in</span> Main at REPL[<span class="hljs-number">34</span>]:<span class="hljs-number">1</span>
[<span class="hljs-number">2</span>] greetuser(user_name) <span class="hljs-keyword">in</span> Main at REPL[<span class="hljs-number">30</span>]:<span class="hljs-number">1</span>
</code></pre>
<p>The built-in <code>methods</code> function is perfect for this and it tells us we have two functions defined, with the only difference being one takes in any type, and the other takes in just a string. </p>
<p>It is worth noting that since we defined a specialized version that accepts just a string, anytime we call the function with a string it will call the specialized version. The more generic function will not be called when a string is passed in.</p>
<p>Next, let us talk about returning values from a function. In Julia, you have two options, you can use the explicit <code>return</code> keyword, or you can opt to do it implicitly by having the last expression in the function serve as the return value like so:</p>
<pre><code class="lang-julia">julia&gt; <span class="hljs-keyword">function</span> sayhi()
           <span class="hljs-string">"This is a test"</span>
           <span class="hljs-string">"hi"</span>
       <span class="hljs-keyword">end</span>
sayhi (generic <span class="hljs-keyword">function</span> with <span class="hljs-number">1</span> method)

julia&gt; sayhi()
<span class="hljs-string">"hi"</span>
</code></pre>
<p>In the above example, the string value "hi" is returned from the function since it is the last expression and there is no explicit return statement. You could also define the function like:</p>
<pre><code class="lang-julia">julia&gt; <span class="hljs-keyword">function</span> sayhi()
           <span class="hljs-string">"This is a test"</span>
          <span class="hljs-keyword">return</span> <span class="hljs-string">"hi"</span>
       <span class="hljs-keyword">end</span>
sayhi (generic <span class="hljs-keyword">function</span> with <span class="hljs-number">1</span> method)

julia&gt; sayhi()
<span class="hljs-string">"hi"</span>
</code></pre>
<p>In general, from a readability standpoint, it makes sense to use the explicit return statement in case someone reading your code does not know about the implicit return behavior in Julia functions.</p>
<p>Another useful functions feature is the ability to provide optional arguments: </p>
<pre><code class="lang-julia">
julia&gt; <span class="hljs-keyword">function</span> sayhello(response=<span class="hljs-string">"hello"</span>)
          <span class="hljs-keyword">return</span> response
       <span class="hljs-keyword">end</span>
sayhello (generic <span class="hljs-keyword">function</span> with <span class="hljs-number">2</span> methods)

julia&gt; sayhello()
<span class="hljs-string">"hello"</span>

julia&gt; sayhello(<span class="hljs-string">"hi"</span>)
<span class="hljs-string">"hi"</span>
</code></pre>
<p>In this example, we define <code>response</code> as an optional argument so that we can either allow it to use the default behavior we defined or we can manually override it when necessary. These examples just scratch the surface on what is possible with functions in Julia. If you want to read more about all the cool things you can do, check out: <a target="_blank" href="https://docs.julialang.org/en/v1/manual/functions/">https://docs.julialang.org/en/v1/manual/functions/</a></p>
<h2 id="heading-how-to-use-packages-in-julia">How to use Packages in Julia 📦</h2>
<p>The Julia package manager and package ecosystem are some of the most important features of the language. I actually wrote an entire article on <a target="_blank" href="https://logankilpatrick.medium.com/the-most-underrated-feature-of-the-julia-programming-language-the-package-manager-652065f45a3a">why it is one of the most underrate features of the language</a>. </p>
<p>With that said, there are two ways to interact with packages in Julia: via the REPL or using the Pkg package. We will mostly focus on the REPL in this post since it is much easier to use in my experience.</p>
<p>After you have Julia installed, you can enter the package manager from the REPL by typing <code>]</code>. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/12/Screen-Shot-2021-12-26-at-9.50.05-AM.png" alt="Image" width="600" height="400" loading="lazy">
<em>Pkg mode in the Julia REPL</em></p>
<p>Now that we are in the package manager, there are a few things we commonly want to do:</p>
<ul>
<li>Add a package</li>
<li>Remove a package</li>
<li>Check what is already installed</li>
</ul>
<p>If you want to see all the possible commands in the REPL, simply enter Pkg mode by typing <code>]</code> and then type <code>?</code>  followed by the enter / return key.</p>
<h3 id="heading-how-to-add-julia-packages">How to Add Julia Packages ➕</h3>
<p>Let’s add our first package, <code>Example.jl</code> . To do so, we can run:</p>
<pre><code class="lang-julia">(<span class="hljs-meta">@v1</span><span class="hljs-number">.7</span>) pkg&gt; add Example
</code></pre>
<p>which should provide output that looks something like:</p>
<pre><code class="lang-julia">(<span class="hljs-meta">@v1</span><span class="hljs-number">.7</span>) pkg&gt; add Example
Updating registry at <span class="hljs-string">`~/.julia/registries/General`</span>
Updating git-repo <span class="hljs-string">`https://github.com/JuliaRegistries/General.git`</span>
Updating registry at <span class="hljs-string">`~/.julia/registries/JuliaPOMDP`</span>
Updating git-repo <span class="hljs-string">`https://github.com/JuliaPOMDP/Registry`</span>
Resolving package versions...
Installed Example ─ v0<span class="hljs-number">.5</span><span class="hljs-number">.3</span>
Updating <span class="hljs-string">`~/.julia/environments/v1.7/Project.toml`</span>
[<span class="hljs-number">7876</span>af07] + Example v0<span class="hljs-number">.5</span><span class="hljs-number">.3</span>
Updating <span class="hljs-string">`~/.julia/environments/v1.7/Manifest.toml`</span>
[<span class="hljs-number">7876</span>af07] + Example v0<span class="hljs-number">.5</span><span class="hljs-number">.3</span>
Precompiling project...
<span class="hljs-number">1</span> dependency successfully precompiled <span class="hljs-keyword">in</span> <span class="hljs-number">1</span> seconds (<span class="hljs-number">69</span> already precompiled)
(<span class="hljs-meta">@v1</span><span class="hljs-number">.7</span>) pkg&gt;
</code></pre>
<p><em>For space reasons, I will skip further outputs under the assumption that you are following along with me.</em></p>
<h3 id="heading-how-to-check-the-package-status-in-julia">How to Check the Package Status in Julia 🔍</h3>
<p>Now that we think we have a package installed, let’s doublecheck if it is really there by typing <code>status</code> (or <code>st</code> for shorthand) into the package manager:</p>
<pre><code class="lang-julia">(<span class="hljs-meta">@v1</span><span class="hljs-number">.7</span>) pkg&gt; st
Status <span class="hljs-string">`~/.julia/environments/v1.7/Project.toml`</span>
[<span class="hljs-number">7876</span>af07] Example v0<span class="hljs-number">.5</span><span class="hljs-number">.3</span>
[<span class="hljs-number">587475</span>ba] Flux v0<span class="hljs-number">.12</span><span class="hljs-number">.8</span>
</code></pre>
<p>Here we can see I have two packages installed, Flux and Example. It also gives me the path to the file which manages my current environment (in this case, global Julia v1.7) along with the package versions I have installed.</p>
<h3 id="heading-how-to-remove-a-julia-package">How to Remove a Julia package 📛</h3>
<p>If I wanted to remove a package from my active environment, like Flux, I can simply type <code>remove Flux</code> (or <code>rm</code> as the shorthand):</p>
<pre><code class="lang-julia">(<span class="hljs-meta">@v1</span><span class="hljs-number">.7</span>) pkg&gt; rm Flux
Updating <span class="hljs-string">`~/.julia/environments/v1.7/Project.toml`</span>
[<span class="hljs-number">587475</span>ba] - Flux v0<span class="hljs-number">.12</span><span class="hljs-number">.8</span>
</code></pre>
<p>A quick <code>status</code> afterward shows this was successful:</p>
<pre><code class="lang-julia">(<span class="hljs-meta">@v1</span><span class="hljs-number">.7</span>) pkg&gt; st
Status <span class="hljs-string">`~/.julia/environments/v1.7/Project.toml`</span>
[<span class="hljs-number">7876</span>af07] Example v0<span class="hljs-number">.5</span><span class="hljs-number">.3</span>
</code></pre>
<p>We now know the very basics of working with packages. But we have committed a major programming crime, using our global package environment. </p>
<h3 id="heading-how-to-use-julia-packages">How to Use Julia Packages 📦</h3>
<p>Now that we have gone over how to manage packages, let’s explore how to use them. Quite simply, you just need to type <code>using packageName</code> to use a specific package you want. One of my favorite new features in Julia 1.7 (highlighted in <a target="_blank" href="https://julialang.org/blog/2021/11/julia-1.7-highlights/">this blog post</a>) is shown below:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/12/1-jI58_UDd87Q4fQ326r6E6Q.png" alt="Image" width="600" height="400" loading="lazy">
<em>Image captured by Author</em></p>
<p>If you recall, we removed the Flux package, and of course, I forgot this so I went to use it and load it in by typing <code>using Flux</code>. The REPL automatically prompts me to install it via a simple "y/n" prompt. This is a small feature but saves a tremendous amount of time and potential confusion.</p>
<p>It is worth noting that there are two ways to access a package's exported functions: via the <code>using</code> keyword and the <code>import</code> keyword. The big difference is that <code>using</code> automatically brings all of the functions into the current namespace (for which you can think about as a big list of functions which Julia knows the definitions) whereas <code>import</code> gives you access to all of the functions but you have to prefix the function with the package name like: <code>Flux.gradient()</code> where <code>Flux</code> is the name of the package and <code>gradient()</code> is the name of a function.</p>
<hr>
<h2 id="heading-how-to-use-structs-in-julia">How to use Structs in Julia?</h2>
<p>Julia does not have Object Orientated Programming (OOP) paradigms built into the language like classes. However, structs in Julia can be used similar to classes to create custom objects and types. Below, we will show a basic example:</p>
<pre><code class="lang-julia">julia&gt; <span class="hljs-keyword">mutable struct</span> dog
           breed::<span class="hljs-built_in">String</span>
           paws::<span class="hljs-built_in">Int</span>
           name::<span class="hljs-built_in">String</span>
           weight::<span class="hljs-built_in">Float64</span>
       <span class="hljs-keyword">end</span>

julia&gt; my_dog = dog(<span class="hljs-string">"Australian Shepard"</span>, <span class="hljs-number">4</span>, <span class="hljs-string">"Indy"</span>, <span class="hljs-number">34.0</span>)
dog(<span class="hljs-string">"Australian Shepard"</span>, <span class="hljs-number">4</span>, <span class="hljs-string">"Indy"</span>, <span class="hljs-number">34.0</span>)

julia&gt; my_dog.name
<span class="hljs-string">"Indy"</span>
</code></pre>
<p>In this example, we define a struct to represent a dog. In the struct, we define four attributes which make up the dog object. In the lines after that, we show the code to actually create a dog object and then access some of its attributes. Note that you need not specify the types of the attributes, you could leave it more open. For this example, we defined explicit types to highlight that feature.</p>
<p>You will notice that similar to classes in Python (and other languages), we did not define an explicit constructor to create the dog object. We can, however, define one if that would be useful to use:</p>
<pre><code class="lang-julia">julia&gt; <span class="hljs-keyword">mutable struct</span> dog
           breed::<span class="hljs-built_in">String</span>
           paws::<span class="hljs-built_in">Int</span>
           name::<span class="hljs-built_in">String</span>
           weight::<span class="hljs-built_in">Float64</span>

           <span class="hljs-keyword">function</span> dog(breed, name, weight, paws=<span class="hljs-number">4</span>)
               new(breed, paws, name, weight)
           <span class="hljs-keyword">end</span>
       <span class="hljs-keyword">end</span>

julia&gt; new_dog = dog(<span class="hljs-string">"German Shepard"</span>, <span class="hljs-string">"Champ"</span>, <span class="hljs-number">46</span>)
dog(<span class="hljs-string">"German Shepard"</span>, <span class="hljs-number">4</span>, <span class="hljs-string">"Champ"</span>, <span class="hljs-number">46.0</span>)
</code></pre>
<p>Here we defined a constructor and used the special keyword <code>new</code> in order to create the object at the end of the function. You can also create getters and setters specifically for the dog object by doing the following:</p>
<pre><code class="lang-julia">julia&gt; <span class="hljs-keyword">function</span> get_name(dog_obj::dog)
           print(<span class="hljs-string">"The dogs's name is: "</span>, dog_obj.name)
       <span class="hljs-keyword">end</span>
get_name (generic <span class="hljs-keyword">function</span> with <span class="hljs-number">1</span> method)

julia&gt; get_name(new_dog)
The dogs's name is: Champ
</code></pre>
<p>In this example, the <code>get_name</code> function only takes an object of type <code>dog</code>. If you try to pass in something else, it will error out:</p>
<pre><code class="lang-julia">julia&gt; get_name(<span class="hljs-string">"test"</span>)
ERROR: <span class="hljs-built_in">MethodError</span>: no method matching get_name(::<span class="hljs-built_in">String</span>)
Closest candidates are:
  get_name(::dog) at REPL[<span class="hljs-number">61</span>]:<span class="hljs-number">1</span>
Stacktrace:
 [<span class="hljs-number">1</span>] top-level scope
   @ REPL[<span class="hljs-number">63</span>]:<span class="hljs-number">1</span>
</code></pre>
<p>It is worth noting that we also defined the struct to be mutable initially so that we could change the field values after we created the object. You omit the keyword <code>mutable</code> if you want the objects initial state to persist.</p>
<p>Structs in Julia not only allow us to create object's, we also are defining a custom type in the process:</p>
<pre><code class="lang-julia">julia&gt; typeof(new_dog)
dog
</code></pre>
<p>In general, structs are used heavily across the Julia ecosystem and you can learn more about them in the docs: <a target="_blank" href="https://docs.julialang.org/en/v1/base/base/#struct">https://docs.julialang.org/en/v1/base/base/#struct</a></p>
<h2 id="heading-additional-julia-programming-learning-resources">Additional Julia Programming Learning Resources 📚</h2>
<p>I hope that this tutorial helped get you up to speed on many of the core ideas of the Julia language. With that said, I know that there are still gaps as this is an extended but non-comprehensive guide. To learn more about Julia, you can check out the learning tab on the Julia website: <a target="_blank" href="https://julialang.org/learning/">https://julialang.org/learning/</a> which has guided courses, YouTube videos, and mentored practice problems. </p>
<p>If you have other questions or need help getting started with Julia, please feel free to get in touch with me: <a target="_blank" href="https://twitter.com/OfficialLoganK">https://twitter.com/OfficialLoganK</a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Which languages should you learn for data science? ]]>
                </title>
                <description>
                    <![CDATA[ By Peter Gleeson Data science is an exciting field to work in, combining advanced statistical and quantitative skills with real-world programming ability. There are many potential programming languages that the aspiring data scientist might consider ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/which-languages-should-you-learn-for-data-science-e806ba55a81f/</link>
                <guid isPermaLink="false">66d460bec7632f8bfbf1e487</guid>
                
                    <category>
                        <![CDATA[ Data Science ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Java ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Julialang ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Matlab ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                    <category>
                        <![CDATA[ R Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Scala ]]>
                    </category>
                
                    <category>
                        <![CDATA[ SQL ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ technology ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Thu, 31 Aug 2017 16:07:30 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*gSxUa9oNaBk1QJf6eqQYeg.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Peter Gleeson</p>
<p>Data science is an exciting field to work in, combining advanced statistical and quantitative skills with real-world programming ability. There are many potential programming languages that the aspiring data scientist might consider specializing in.</p>
<p>While there is no correct answer, there are several things to take into consideration. Your success as a data scientist will depend on many points, including:</p>
<p><strong>Specificity</strong></p>
<p>When it comes to advanced data science, you will only get so far reinventing the wheel each time. Learn to master the various packages and modules offered in your chosen language. The extent to which this is possible depends on what domain-specific packages are available to you in the first place!</p>
<p><strong>Generality</strong></p>
<p>A top data scientist will have good all-round programming skills as well as the ability to crunch numbers. Much of the day-to-day work in data science revolves around sourcing and processing raw data or ‘data cleaning’. For this, no amount of fancy machine learning packages are going to help.</p>
<p><strong>Productivity</strong></p>
<p>In the often fast-paced world of commercial data science, there is much to be said for getting the job done quickly. However, this is what enables technical debt to creep in — and only with sensible practices can this be minimized.</p>
<p><strong>Performance</strong></p>
<p>In some cases it is vital to optimize the performance of your code, especially when dealing with large volumes of mission-critical data. Compiled languages are typically much faster than interpreted ones; likewise statically typed languages are considerably more fail-proof than dynamically typed. The obvious trade-off is against productivity.</p>
<p>To some extent, these can be seen as a pair of axes (Generality-Specificity, Performance-Productivity). Each of the languages below fall somewhere on these spectra.</p>
<p>With these core principles in mind, let’s take a look at some of the more popular languages used in data science. What follows is a combination of research and personal experience of myself, friends and colleagues — but it is by no means definitive! In approximately order of popularity, here goes:</p>
<h3 id="heading-r">R</h3>
<h4 id="heading-what-you-need-to-know">What you need to know</h4>
<p><img src="https://cdn-media-1.freecodecamp.org/images/bx3wt1sCBXSEUkiii81wH31gLcU0e3XiA6S7" alt="Image" width="256" height="256" loading="lazy"></p>
<p>Released in 1995 as a direct descendant of the older S programming language, R has since gone from strength to strength. Written in C, Fortran and itself, the project is currently supported by the <a target="_blank" href="https://www.r-project.org/foundation/">R Foundation for Statistical Computing</a>.</p>
<h4 id="heading-license">License</h4>
<p>Free!</p>
<h4 id="heading-pros">Pros</h4>
<ul>
<li>Excellent range of high-quality, domain specific and <a target="_blank" href="https://cran.r-project.org/">open source packages</a>. R has a package for almost every quantitative and statistical application imaginable. This includes neural networks, non-linear regression, phylogenetics, advanced plotting and many, many others.</li>
<li>The base installation comes with very comprehensive, in-built statistical functions and methods. R also handles matrix algebra particularly well.</li>
<li>Data visualization is a key strength with the use of libraries such as <a target="_blank" href="http://ggplot2.org/">ggplot2</a>.</li>
</ul>
<h4 id="heading-cons">Cons</h4>
<ul>
<li>Performance. There’s no two ways about it, <a target="_blank" href="http://adv-r.had.co.nz/Performance.html">R is not a quick language</a>.</li>
<li>Domain specificity. R is fantastic for statistics and data science purposes. But less so for general purpose programming.</li>
<li>Quirks. R has a few unusual features that might catch out programmers experienced with other languages. For instance: indexing from 1, using multiple assignment operators, unconventional data structures.</li>
</ul>
<h4 id="heading-verdict-brilliant-at-what-its-designed-for">Verdict — “brilliant at what it’s designed for”</h4>
<p>R is a powerful language that excels at a huge variety of statistical and data visualization applications, and being open source allows for a very active community of contributors. Its recent growth in popularity is a testament to how effective it is at what it does.</p>
<h3 id="heading-python">Python</h3>
<h4 id="heading-what-you-need-to-know-1">What you need to know</h4>
<p><img src="https://cdn-media-1.freecodecamp.org/images/U0XPlJp-xNFQypL6euOVZKDgms1Rfk4Hiojy" alt="Image" width="250" height="250" loading="lazy"></p>
<p>Guido van Rossum introduced Python back in 1991. It has since become an extremely popular general purpose language, and is widely used within the data science community. The major versions are currently <a target="_blank" href="https://www.python.org/downloads/release/python-362/">3.6</a> and <a target="_blank" href="https://www.python.org/download/releases/2.7/">2.7</a>.</p>
<h4 id="heading-license-1">License</h4>
<p>Free!</p>
<h4 id="heading-pros-1">Pros</h4>
<ul>
<li>Python is a very popular, mainstream general purpose programming language. It has an <a target="_blank" href="https://pypi.python.org/pypi">extensive range of purpose-built modules</a> and community support. Many online services provide a Python API.</li>
<li>Python is an easy language to learn. The low barrier to entry makes it an ideal first language for those new to programming.</li>
<li>Packages such as <a target="_blank" href="http://pandas.pydata.org/">pandas</a>, <a target="_blank" href="http://scikit-learn.org/stable/">scikit-learn</a> and <a target="_blank" href="https://www.tensorflow.org/">Tensorflow</a> make Python a solid option for advanced machine learning applications.</li>
</ul>
<h4 id="heading-cons-1">Cons</h4>
<ul>
<li>Type safety: Python is a dynamically typed language, which means you must show due care. Type errors (such as passing a String as an argument to a method which expects an Integer) are to be expected from time-to-time.</li>
<li>For specific statistical and data analysis purposes, R’s vast range of packages gives it a slight edge over Python. For general purpose languages, there are faster and safer alternatives to Python.</li>
</ul>
<h4 id="heading-verdict-excellent-all-rounder">Verdict — “excellent all-rounder”</h4>
<p>Python is a very good choice of language for data science, and not just at entry-level. Much of the data science process revolves around the <a target="_blank" href="https://en.wikipedia.org/wiki/Extract,_transform,_load">ETL process</a> (extraction-transformation-loading). This makes Python’s generality ideally suited. Libraries such as Google’s Tensorflow make Python a very exciting language to work in for machine learning.</p>
<h3 id="heading-sql">SQL</h3>
<h4 id="heading-what-you-need-to-know-2">What you need to know</h4>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1Dbg8u7RSmjx8l-Xv7DMDJpesKUYKEVASvP6" alt="Image" width="190" height="221" loading="lazy"></p>
<p><a target="_blank" href="https://www.w3schools.com/sql/default.asp">SQL</a> (‘Structured Query Language’) defines, manages and queries <a target="_blank" href="https://en.wikipedia.org/wiki/Relational_database">relational databases</a>. The language appeared by 1974 and has since undergone many implementations, but the core principles remain the same.</p>
<h4 id="heading-license-2">License</h4>
<p>Varies — some implementations are free, others proprietary</p>
<h4 id="heading-pros-2">Pros</h4>
<ul>
<li>Very efficient at querying, updating and manipulating relational databases.</li>
<li>Declarative syntax makes SQL an often very readable language . There’s no ambiguity about what <code>SELECT name FROM users WHERE age &gt;</code> 18 is supposed to do!</li>
<li>SQL is very used across a range of applications, making it a very useful language to be familiar with. Modules such as <a target="_blank" href="https://www.sqlalchemy.org/">SQLAlchemy</a> make integrating SQL with other languages straightforward.</li>
</ul>
<h4 id="heading-cons-2">Cons</h4>
<ul>
<li>SQL’s analytical capabilities are rather limited — beyond aggregating and summing, counting and averaging data, your options are limited.</li>
<li>For programmers coming from an imperative background, SQL’s declarative syntax can present a learning curve.</li>
<li>There are many different implementations of SQL such as <a target="_blank" href="https://www.postgresql.org/">PostgreSQL</a>, <a target="_blank" href="https://www.sqlite.org/">SQLite</a>, <a target="_blank" href="https://mariadb.org/">MariaDB</a> . They are all different enough to make inter-operability something of a headache.</li>
</ul>
<h4 id="heading-verdict-timeless-and-efficient">Verdict — “timeless and efficient”</h4>
<p>SQL is more useful as a data processing language than as an advanced analytical tool. Yet so much of the data science process hinges upon ETL, and SQL’s longevity and efficiency are proof that it is a very useful language for the modern data scientist to know.</p>
<h3 id="heading-java">Java</h3>
<h4 id="heading-what-you-need-to-know-3">What you need to know</h4>
<p><img src="https://cdn-media-1.freecodecamp.org/images/E2x8C0ZeF7QXqbkewzZdLlXojOkcMP16sayQ" alt="Image" width="256" height="256" loading="lazy"></p>
<p>Java is an extremely popular, general purpose language which runs on the (JVM) Java Virtual Machine. It’s an abstract computing system that enables seamless portability between platforms. Currently supported by <a target="_blank" href="https://www.oracle.com/java/index.html">Oracle Corporation</a>.</p>
<h4 id="heading-license-3">License</h4>
<p>Version 8 — Free! Legacy versions, proprietary.</p>
<h4 id="heading-pros-3">Pros</h4>
<ul>
<li>Ubiquity . Many modern systems and applications are built upon a Java back-end. The ability to integrate data science methods directly into the existing codebase is a powerful one to have.</li>
<li>Strongly typed. Java is no-nonsense when it comes to ensuring type safety. For mission-critical big data applications, this is invaluable.</li>
<li>Java is a high-performance, general purpose, compiled language . This makes it suitable for writing efficient ETL production code and computationally intensive machine learning algorithms.</li>
</ul>
<h4 id="heading-cons-3">Cons</h4>
<ul>
<li>For ad-hoc analyses and more dedicated statistical applications, Java’s verbosity makes it an unlikely first choice. Dynamically typed scripting languages such as R and Python lend themselves to much greater productivity.</li>
<li>Compared to domain-specific languages like R, there aren’t a great number of libraries available for advanced statistical methods in Java.</li>
</ul>
<h4 id="heading-verdict-a-serious-contender-for-data-science">Verdict — “a serious contender for data science”</h4>
<p>There is a lot to be said for learning Java as a first choice data science language. Many companies will appreciate the ability to seamlessly integrate data science production code directly into their existing codebase, and you will find Java’s performance and and type safety are real advantages. </p>
<p>However, you’ll be without the range of stats-specific packages available to other languages. That said, definitely one to consider — especially if you already know one of R and/or Python.</p>
<h3 id="heading-scala">Scala</h3>
<h4 id="heading-what-you-need-to-know-4">What you need to know</h4>
<p><img src="https://cdn-media-1.freecodecamp.org/images/ttyRkvz1Ye6LkeZdGzMZmesaG2BcvGZhFcmV" alt="Image" width="250" height="250" loading="lazy"></p>
<p>Developed by Martin Odersky and released in 2004, <a target="_blank" href="https://www.scala-lang.org/">Scala</a> is a language which runs on the JVM. It is a multi-paradigm language, enabling both object-oriented and functional approaches. Cluster computing framework <a target="_blank" href="https://spark.apache.org/">Apache Spark</a> is written in Scala.</p>
<h4 id="heading-license-4">License</h4>
<p>Free!</p>
<h4 id="heading-pros-4">Pros</h4>
<ul>
<li>Scala + Spark = High performance cluster computing. Scala is an ideal choice of language for those working with high-volume data sets.</li>
<li>Multi-paradigmatic: Scala programmers can have the best of both worlds. Both object-oriented and functional programming paradigms available to them.</li>
<li>Scala is compiled to Java bytecode and runs on a JVM. This allows inter-operability with the Java language itself, making Scala a very powerful general purpose language, while also being well-suited for data science.</li>
</ul>
<h4 id="heading-cons-4">Cons</h4>
<ul>
<li>Scala is not a straightforward language to get up and running with if you’re just starting out. Your best bet is to download <a target="_blank" href="http://www.scala-sbt.org/">sbt</a> and set up an IDE such as Eclipse or IntelliJ with a specific Scala plug-in.</li>
<li>The syntax and type system are often described as complex. This makes for a steep learning curve for those coming from dynamic languages such as Python.</li>
</ul>
<h4 id="heading-verdict-perfect-for-suitably-big-data">Verdict — “perfect, for suitably big data”</h4>
<p>When it comes to using cluster computing to work with Big Data, then Scala + Spark are fantastic solutions. If you have experience with Java and other statically typed languages, you’ll appreciate these features of Scala too. </p>
<p>Yet if your application doesn’t deal with the volumes of data that justify the added complexity of Scala, you will likely find your productivity being much higher using other languages such as R or Python.</p>
<h3 id="heading-julia">Julia</h3>
<h4 id="heading-what-you-need-to-know-5">What you need to know</h4>
<p><img src="https://cdn-media-1.freecodecamp.org/images/Ok4VqC5ra015oGgqPcuGvJ9cWBtBu5f0Zt-G" alt="Image" width="370" height="208" loading="lazy"></p>
<p>Released just over 5 years ago, <a target="_blank" href="https://julialang.org/">Julia</a> has made an impression in the world of numerical computing. Its profile was raised thanks to early adoption by <a target="_blank" href="https://juliacomputing.com/case-studies/">several major organizations</a> including many in the finance industry.</p>
<h4 id="heading-license-5">License</h4>
<p>Free!</p>
<h4 id="heading-pros-5">Pros</h4>
<ul>
<li>Julia is a JIT (‘just-in-time’) compiled language, which lets it offer good performance. It also offers the simplicity, dynamic-typing and scripting capabilities of an interpreted language like Python.</li>
<li>Julia was purpose-designed for numerical analysis. It is capable of general purpose programming as well.</li>
<li>Readability. Many users of the language cite this as a key advantage</li>
</ul>
<h4 id="heading-cons-5">Cons</h4>
<ul>
<li>Maturity. As a new language, some Julia users have experienced instability when using packages. But the core language itself is reportedly stable enough for production use.</li>
<li>Limited packages are another consequence of the language’s youthfulness and small development community. Unlike long-established R and Python, Julia doesn’t have the choice of packages (yet).</li>
</ul>
<h4 id="heading-verdict-one-for-the-future">Verdict — “one for the future”</h4>
<p>The main issue with Julia is one that cannot be blamed for. As a recently developed language, it isn’t as mature or production-ready as its main alternatives Python and R.</p>
<p>But, if you are willing to be patient, there’s every reason to pay close attention as the language evolves in the coming years.</p>
<h3 id="heading-matlab">MATLAB</h3>
<h4 id="heading-what-you-need-to-know-6">What you need to know</h4>
<p><img src="https://cdn-media-1.freecodecamp.org/images/DI1Fj8dKXe484TVK6JSHSKeuYPPfE49rIwYI" alt="Image" width="225" height="225" loading="lazy"></p>
<p><a target="_blank" href="https://in.mathworks.com/products/matlab.html">MATLAB</a> is an established numerical computing language used throughout academia and industry. It is developed and licensed by MathWorks, a company established in 1984 to commercialize the software.</p>
<h4 id="heading-license-6">License</h4>
<p>Proprietary — pricing varies depending on your use case</p>
<h4 id="heading-pros-6">Pros</h4>
<ul>
<li>Designed for numerical computing. MATLAB is well-suited for quantitative applications with sophisticated mathematical requirements such as signal processing, Fourier transforms, matrix algebra and image processing.</li>
<li>Data Visualization. MATLAB has some great inbuilt plotting capabilities.</li>
<li>MATLAB is often taught as part of many undergraduate courses in quantitative subjects such as Physics, Engineering and Applied Mathematics. As a consequence, it is widely used within these fields.</li>
</ul>
<h4 id="heading-cons-6">Cons</h4>
<ul>
<li>Proprietary licence. Depending on your use-case (academic, personal or enterprise) you may have to fork out for a pricey licence. There are free alternatives available such as <a target="_blank" href="https://www.gnu.org/software/octave/">Octave</a>. This is something you should give real consideration to.</li>
<li>MATLAB isn’t an obvious choice for general-purpose programming.</li>
</ul>
<h4 id="heading-verdict-best-for-mathematically-intensive-applications">Verdict — “best for mathematically intensive applications”</h4>
<p>MATLAB’s widespread use in a range of quantitative and numerical fields throughout industry and academia makes it a serious option for data science. </p>
<p>The clear use-case would be when your application or day-to-day role requires intensive, advanced mathematical functionality. Indeed, MATLAB was specifically designed for this.</p>
<h3 id="heading-other-languages">Other Languages</h3>
<p>There are other mainstream languages that may or may not be of interest to data scientists. This section provides a quick overview… with plenty of room for debate of course!</p>
<h4 id="heading-c">C++</h4>
<p><a target="_blank" href="https://isocpp.org/">C++</a> is not a common choice for data science, although it has lightning fast performance and widespread mainstream popularity. The simple reason may be a question of productivity versus performance.</p>
<p>As <a target="_blank" href="https://www.quora.com/Why-dont-data-scientists-use-C-C%2B%2B/answer/Kevin-Lin?srid=hhtiJ">one Quora user puts it</a>:</p>
<blockquote>
<p><em>“If you’re writing code to do some ad-hoc analysis that will probably only be run one time, would you rather spend 30 minutes writing a program that will run in 10 seconds, or 10 minutes writing a program that will run in 1 minute?”</em></p>
</blockquote>
<p>The dude’s got a point. Yet for serious production-level performance, C++ would be an excellent choice for implementing machine learning algorithms optimized at a low-level.</p>
<p><strong>Verdict — “not for day-to-day work, but if performance is critical…”</strong></p>
<h4 id="heading-javascript">JavaScript</h4>
<p>With the rise of <a target="_blank" href="https://nodejs.org/en/">Node.js</a> in recent years, <a target="_blank" href="https://en.wikipedia.org/wiki/JavaScript">JavaScript</a> has become more and more a serious server-side language. However, its use in data science and machine learning domains has been limited to date (although checkout <a target="_blank" href="https://github.com/harthur/brain">brain.js</a> and <a target="_blank" href="http://caza.la/synaptic/#/">synaptic.js</a>!). It suffers from the following disadvantages:</p>
<ul>
<li>Late to the game (Node.js is only 8 years old!), meaning…</li>
<li>Few relevant data science libraries and modules are available. This means no real mainstream interest or momentum</li>
<li>Performance-wise, Node.js is quick. But JavaScript as a language is <a target="_blank" href="https://hackernoon.com/the-javascript-phenomenon-is-a-mass-psychosis-57adebb09359">not without its critics</a>.</li>
</ul>
<p>Node’s strengths are in asynchronous I/O, its widespread use and the existence of <a target="_blank" href="https://www.slant.co/topics/101/~best-languages-that-compile-to-javascript">languages which compile to JavaScript</a>. So it’s conceivable that a useful framework for data science and realtime ETL processing could come together. </p>
<p>The key question is whether this would offer anything different to what already exists.</p>
<p><strong>Verdict — “there is much to do before JavaScript can be taken as a serious data science language”</strong></p>
<h4 id="heading-perl"><strong>Perl</strong></h4>
<p><a target="_blank" href="https://www.perl.org/">Perl</a> is known as a ‘Swiss-army knife of programming languages’, due to its versatility as a general-purpose scripting language. It shares a lot in common with Python, being a dynamically typed scripting language. But, it has not seen anything like the popularity Python has in the field of data science.</p>
<p>This is a little surprising, given its use in quantitative fields such as <a target="_blank" href="https://en.wikipedia.org/wiki/BioPerl">bioinformatics</a>. Perl has several key disadvantages when it comes to data science. It isn’t stand-out fast, and its syntax is <a target="_blank" href="https://en.wikipedia.org/wiki/Write-only_language">famously unfriendly</a>. There hasn’t been the same drive towards developing data science specific libraries. And in any field, momentum is key.</p>
<p><strong>Verdict — “a useful general purpose scripting language, yet it offers no real advantages for your data science CV”</strong></p>
<h4 id="heading-ruby">Ruby</h4>
<p><a target="_blank" href="https://www.ruby-lang.org/en/">Ruby</a> is another general purpose, dynamically typed interpreted language. Yet it also hasn’t seen the same adoption for data science as has Python.</p>
<p>This might seem surprising, but is likely a result of Python’s dominance in academia, and a positive feedback effect . The more people use Python, the more modules and frameworks are developed, and the more people will turn to Python. </p>
<p>The <a target="_blank" href="http://sciruby.com/">SciRuby project</a> exists to bring scientific computing functionality, such as matrix algebra, to Ruby. But for the time being, Python still leads the way.</p>
<p><strong>Verdict — “not an obvious choice yet for data science, but won’t harm the CV”</strong></p>
<h3 id="heading-conclusion">Conclusion</h3>
<p>Well, there you have it — a quickfire guide to which languages to consider for data science. The key here is to understand your usage requirements in terms of generality vs specificity, as well as your personal preferred development style of performance vs productivity.</p>
<p>I use R, Python and SQL on a regular basis, as my current role largely focuses on developing existing data pipeline and ETL processes. These languages give the right balance of generality and productivity to do the job, with the option of using R’s more advanced statistics packages when needed.</p>
<p>However — you may already have some experience with Java. Or you may want to use Scala for big data. Or, perhaps you’re keen to get involved with the Julia project.</p>
<p>Maybe you learned MATLAB at university, or want to give SciRuby a chance? Perhaps you have an altogether different suggestion. If so, please leave a reply below — I look forward to hearing from you!</p>
<p>Thanks for reading!</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
