Comprehensions And Filter Vs. For and Continue in Julia
<p>Those that have been reading my blog somewhat consistency might recall a short article I wrote a few months ago discussing how I nearly never use traditional for loops when programming Julia. The primary techniques I use to replace these loops are often either mapping or comprehensions. Julia has a rather robust comprehension syntax that makes it incredibly easy to do just about anything inside of a comprehension. Taking a look at some of my code, this code from <a href="https://github.com/ChifiSource/Olive.jl" rel="noopener ugc nofollow" target="_blank">Olive.jl</a>, it is clear this is a practice I follow most of the time.</p>
<p><img alt="" src="https://miro.medium.com/v2/resize:fit:541/1*RwxoCqDDxtmA3n97uChxbQ.png" style="height:507px; width:601px" /></p>
<p>I tend to use comprehensions because they are faster than most other techniques in Julia, and with the <code>begin/end</code> syntax seen above, it is also incredibly legible! While it might often be the case that I write something this way, this is not a rule — there are plenty of examples in this very file where I utilize for loops, for example this function:</p>
<p><a href="https://chifi.dev/comprehensions-and-filter-vs-for-and-continue-in-julia-78741bf1f9cf">Visit Now</a></p>