<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kerron Parchment on Medium]]></title>
        <description><![CDATA[Stories by Kerron Parchment on Medium]]></description>
        <link>https://medium.com/@kerronp?source=rss-ed0c554f169f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*_PP3no3O2DexZLmxoZ7oyg.png</url>
            <title>Stories by Kerron Parchment on Medium</title>
            <link>https://medium.com/@kerronp?source=rss-ed0c554f169f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 14:49:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kerronp/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A Functional Love Affair: Why I Chose Haskell Over JavaScript]]></title>
            <link>https://medium.com/@kerronp/a-functional-love-affair-why-i-chose-haskell-over-javascript-fe9b2c619c42?source=rss-ed0c554f169f------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe9b2c619c42</guid>
            <category><![CDATA[haskell]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Kerron Parchment]]></dc:creator>
            <pubDate>Thu, 01 Jun 2023 14:01:50 GMT</pubDate>
            <atom:updated>2023-06-01T14:01:50.220Z</atom:updated>
            <content:encoded><![CDATA[<p>As a developer with a strong background in JavaScript, I have always been fascinated by the versatility and power of this scripting language. However, my passion for programming led me to explore other languages that could offer unique benefits and features. That’s when I stumbled upon Haskell, a purely functional programming language that has quickly become my favourite. In this article, I will share my experience with Haskell, compare it with JavaScript, and provide code examples to demonstrate why Haskell has won me over.</p><h3>Haskell vs. JavaScript: Key Differences</h3><h4>1. Paradigm</h4><p>The most significant difference between Haskell and JavaScript lies in their programming paradigms. JavaScript is a multi-paradigm language, supporting imperative, object-oriented, and functional programming styles. On the other hand, Haskell is a purely functional programming language that emphasises immutability, lazy evaluation, and strong static typing.</p><h4>2. Syntax</h4><p>Haskell’s syntax is clean, concise, and elegant, which makes it more comfortable to read and write. JavaScript’s syntax is derived from C, which can be more verbose and cluttered with curly braces and semicolons.</p><h4>3. Type System</h4><p>Haskell has a strong, static type system that can catch many errors at compile-time, preventing them from causing issues at runtime. JavaScript, however, is dynamically typed, which means that type checking occurs at runtime and can lead to unexpected errors.</p><h4>4. Concurrency and Parallelism</h4><p>Haskell offers advanced concurrency and parallelism features through its libraries, such as the async package and Control.Concurrent. JavaScript&#39;s single-threaded event-driven model relies on asynchronous callbacks, promises, or async/await for handling concurrency. While JavaScript has Web Workers for parallelism, they have limited interaction with the main thread and require message passing.</p><h4>5. Pattern Matching</h4><p>Haskell provides powerful pattern matching capabilities, which can greatly simplify code and make it more expressive. JavaScript does not have native pattern matching support, although recent additions like destructuring assignment can achieve similar results in some cases.</p><h3>Code Examples</h3><h4>1. Function Definitions</h4><p>In Haskell, function definitions are concise and easy to read:</p><pre>add :: Int -&gt; Int -&gt; Int<br>add x y = x + y</pre><p>In JavaScript, the equivalent function would look like this:</p><pre>function add(x, y) {<br>  return x + y;<br>}</pre><h4>2. Higher-Order Functions</h4><p>Haskell’s functional nature makes it easy to create and use higher-order functions:</p><pre>map :: (a -&gt; b) -&gt; [a] -&gt; [b]<br>map _ [] = []<br>map f (x:xs) = f x : map f xs</pre><p>In JavaScript, we can achieve the same using Array.prototype.map:</p><pre>function map(f, arr) {<br>  return arr.map(f);<br>}</pre><h4>3. Immutability</h4><p>Haskell enforces immutability, which prevents bugs related to mutable data:</p><pre>incrementAll :: [Int] -&gt; [Int]<br>incrementAll [] = []<br>incrementAll (x:xs) = (x + 1) : incrementAll xs</pre><p>In JavaScript, we can achieve immutability using functional programming techniques:</p><pre>function incrementAll(arr) {<br>  return arr.map(x =&gt; x + 1);<br>}</pre><h4>4. Pattern Matching</h4><p>Haskell supports pattern matching, which is a powerful way to destructure data and apply logic based on data patterns:</p><pre>factorial :: Int -&gt; Int<br>factorial 0 = 1<br>factorial n = n * factorial (n - 1)</pre><p>In JavaScript, we can use a combination of if statements and recursion to achieve the same:</p><pre>function factorial(n) {<br>  if (n === 0) {<br>    return 1;<br>  } else {<br>    return n * factorial(n - 1);<br>  }<br>}</pre><h4>5. Currying</h4><p>In Haskell, all functions are curried by default, which means we can easily create partial applications. For example, consider the following function that adds two numbers:</p><pre>add :: Int -&gt; Int -&gt; Int<br>add x y = x + y</pre><p>We can partially apply the add function to create a new function that increments a number by one:</p><pre>increment :: Int -&gt; Int<br>increment = add 1</pre><p>In JavaScript, we can achieve currying using closures:</p><pre>function add(x) {<br>  return function(y) {<br>    return x + y;<br>  };<br>}<br><br>const increment = add(1);</pre><h4>6. Laziness</h4><p>Laziness, or lazy evaluation, is a key feature of Haskell that postpones the computation of an expression until its value is required. This allows Haskell to avoid unnecessary calculations, reduce memory consumption, and create infinite data structures.</p><p>Haskell’s laziness is achieved through the use of thunks, which are unevaluated expressions that are stored in memory until their values are needed. Once a thunk is evaluated, its value is cached to prevent redundant calculations.</p><p>Let’s consider an example that demonstrates the benefits of lazy evaluation. In Haskell, we can create an infinite list of Fibonacci numbers:</p><pre>fibonacci :: [Integer]<br>fibonacci = 0 : 1 : zipWith (+) fibonacci (tail fibonacci)</pre><p>Despite being an infinite list, Haskell’s lazy evaluation allows us to work with it efficiently. We can easily take the first ten Fibonacci numbers without computing the entire list:</p><pre>take 10 fibonacci</pre><p>In JavaScript, achieving this level of laziness requires a more complex implementation, often using generators:</p><pre>function* fibonacci() {<br>  let [a, b] = [0, 1];<br>  while (true) {<br>    yield a;<br>    [a, b] = [b, a + b];<br>  }<br>}<br><br>function take(n, iterable) {<br>  const result = [];<br>  const iterator = iterable[Symbol.iterator]();<br><br>  for (let i = 0; i &lt; n; i++) {<br>    const { value, done } = iterator.next();<br>    if (done) break;<br>    result.push(value);<br>  }<br><br>  return result;<br>}<br><br>const firstTenFibonacci = take(10, fibonacci());</pre><p>Currying and laziness are two powerful features that set Haskell apart from JavaScript, making it an attractive choice for developers seeking more elegant and efficient code. These features contribute to Haskell’s clean, expressive syntax and ability to handle complex computations with ease.</p><h4>7. Type Inference and Polymorphism</h4><p>Haskell’s type inference allows for cleaner and more concise code by letting the compiler automatically deduce the types of expressions and functions. This feature helps developers focus on writing the logic without the need for explicit type annotations in many cases.</p><p>In addition to type inference, Haskell offers polymorphism through type classes. Type classes define a set of functions that a type must implement, allowing for more reusable and adaptable code. This is similar to interfaces in object-oriented programming languages.</p><p>Example of type class in Haskell:</p><pre>class Eq a where<br>    (==) :: a -&gt; a -&gt; Bool<br>    (/=) :: a -&gt; a -&gt; Bool</pre><h4>8. Error Handling with Monads</h4><p>Error handling in Haskell is fundamentally different from JavaScript. Haskell uses monads, such as the Either and Maybe types, for a functional and composable approach to error handling, side effects, and other actions with potentially different outcomes.</p><p>For example, consider the following Haskell code that uses the Maybe monad to handle potential failure when looking up a value in a list:</p><pre>lookup :: Eq a =&gt; a -&gt; [(a, b)] -&gt; Maybe b<br>lookup _ [] = Nothing<br>lookup key ((x, y) : xys)<br>  | key == x = Just y<br>  | otherwise = lookup key xys</pre><h3>Real-World Applications and Libraries</h3><p>Haskell has a rich ecosystem of libraries and frameworks for various real-world applications:</p><ul><li>Yesod: A web development framework (<a href="https://www.yesodweb.com/">https://www.yesodweb.com/</a>)</li><li>Parsec: An advanced parsing library (<a href="https://hackage.haskell.org/package/parsec">https://hackage.haskell.org/package/parsec</a>)</li><li>STM: Software Transactional Memory for concurrent programming (<a href="https://hackage.haskell.org/package/stm">https://hackage.haskell.org/package/stm</a>)</li></ul><h3>Transitioning from JavaScript to Haskell</h3><p>Tips and advice for JavaScript developers who want to learn Haskell:</p><ul><li>Familiarise yourself with functional programming concepts</li><li>Start with small, manageable projects in Haskell</li><li>Be patient and persistent, as Haskell has a steep learning curve</li><li>Engage with the Haskell community for support and guidance</li></ul><h3>Conclusion</h3><p>Haskell’s functional purity, elegant syntax, strong static typing, and emphasis on immutability make it an appealing choice for programmers who want to write clean, maintainable, and efficient code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe9b2c619c42" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Basic Mathematical Operations in Haskell and : A Simple Tutorial]]></title>
            <link>https://medium.com/@kerronp/basic-mathematical-operations-in-haskell-and-a-simple-tutorial-6a5c2e427575?source=rss-ed0c554f169f------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a5c2e427575</guid>
            <category><![CDATA[codewars]]></category>
            <category><![CDATA[haskell-programming]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[haskell]]></category>
            <category><![CDATA[clojure]]></category>
            <dc:creator><![CDATA[Kerron Parchment]]></dc:creator>
            <pubDate>Thu, 01 Jun 2023 14:01:49 GMT</pubDate>
            <atom:updated>2023-06-01T14:01:49.040Z</atom:updated>
            <content:encoded><![CDATA[<h3>Basic Mathematical Operations in Haskell and Clojure: A Simple Tutorial</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YLkJ6FLtZxoUL66-" /><figcaption>Photo by <a href="https://unsplash.com/@jstrippa?utm_source=medium&amp;utm_medium=referral">James Harrison</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>In this tutorial, we will explore how to create a concise function in Haskell that performs four basic mathematical operations: addition, subtraction, multiplication, and division, using integers.</p><p>This function will accept three arguments: the operation (a character) and two integer values. It will then return the result of the operation applied to the two input numbers. This is based on the CodeWars problem <a href="https://www.codewars.com/kata/57356c55867b9b7a60000bd7/haskell">here</a>.</p><h3>The BasicMath Function in Haskell</h3><p>To get started, let’s take a look at the code for our basicOp function that works with Int type:</p><pre>basicOp :: Char -&gt; Int -&gt; Int -&gt; Int<br>basicOp &#39;+&#39; = (+)<br>basicOp &#39;-&#39; = (-)<br>basicOp &#39;*&#39; = (*)<br>basicOp &#39;/&#39; = div</pre><p>The function takes a character op representing the operation and two Int numbers. Instead of using guards or pattern matching, we directly define the function using partial application. We assign each operation symbol to its corresponding Haskell function: (+) for addition, (-) for subtraction, (*) for multiplication, and div for integer division.</p><p>This concise syntax leverages Haskell’s higher-order functions and point-free style to create a compact and elegant solution.</p><h4>Testing the Function</h4><p>To test the basicOp function, you can create a main function that calls it with different operations and numeric values, like so:</p><pre>main :: IO ()<br>main = do<br>  putStrLn &quot;Testing basicOp function:&quot;<br>  print (basicOp &#39;+&#39; 4 7)  -- Output: 11<br>  print (basicOp &#39;-&#39; 15 18) -- Output: -3<br>  print (basicOp &#39;*&#39; 5 5)   -- Output: 25<br>  print (basicOp &#39;/&#39; 49 7)  -- Output: 7</pre><h3>The BasicMath Function in Clojure</h3><p>To create the same function in Clojure, we can use the following code:</p><pre>(defn basic-math [op value1 value2]<br>  (cond<br>    (= op \+) (+ value1 value2)<br>    (= op \-) (- value1 value2)<br>    (= op \*) (* value1 value2)<br>    (= op \/) (/ value1 value2)<br>    :else (throw (ex-info &quot;Invalid operator&quot; {}))))</pre><p>The function takes a character op representing the operation, and two numbers value1 and value2. We use the cond macro to match the operation and perform the corresponding calculation. If an invalid operator is provided, an exception is thrown with an error message.</p><h4>Testing the Function in Clojure</h4><p>To test the basic-math function, you can create a main function that calls it with different operations and numeric values, like so:</p><pre>(defn -main []<br>  (println &quot;Testing basic-math function:&quot;)<br>  (println (basic-math \+ 4 7))  ; Output: 11<br>  (println (basic-math \- 15 18)) ; Output: -3<br>  (println (basic-math \* 5 5))   ; Output: 25<br>  (println (basic-math \/ 49 7))) ; Output: 7</pre><p>Note that we use the backslash \ to represent characters in Clojure.</p><h3>Conclusion</h3><p>we have learned how to create functions in Haskell and Clojure that perform four basic mathematical operations: addition, subtraction, multiplication, and division. Both languages offer concise and elegant solutions that leverage their respective strengths.</p><p>In Haskell, we use guards to match the operation symbol and perform the corresponding calculation. Haskell’s strong type system ensures that we can handle different types of input values and prevent runtime errors.</p><p>In Clojure, we use the cond macro to match the operation symbol and perform the corresponding calculation. Clojure&#39;s functional approach and Lisp syntax make it easy to reason about and maintain complex algorithms.</p><p>With these functions, you can build more complex programs that perform various mathematical operations on numeric data. You can extend these functions to support more operations or custom input validation as needed.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a5c2e427575" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Semicolon in Programming: Its Origins, Influence, and Enduring Presence]]></title>
            <link>https://medium.com/@kerronp/the-semicolon-in-programming-its-origins-influence-and-enduring-presence-a00165ae331e?source=rss-ed0c554f169f------2</link>
            <guid isPermaLink="false">https://medium.com/p/a00165ae331e</guid>
            <category><![CDATA[software-history]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[semi-colon]]></category>
            <dc:creator><![CDATA[Kerron Parchment]]></dc:creator>
            <pubDate>Mon, 01 May 2023 14:01:49 GMT</pubDate>
            <atom:updated>2023-05-01T14:01:49.704Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yj_n7SvN7dbZtfvYsGhSdQ.png" /></figure><p>The semicolon has played a significant role in computer programming since the early days of high-level programming languages. While its role as a statement separator or terminator may seem trivial, the semicolon has contributed to the clarity, readability, and organisation of countless programs over the years. In this article, we explore the origins of the semicolon in programming, its influence on the design of subsequent programming languages, and its enduring presence in the syntax of modern languages.</p><h3>Introduction</h3><p>The use of the semicolon in programming can be traced back to the ALGOL family of languages, particularly ALGOL 60. ALGOL 60 was designed by an international committee of computer scientists, mathematicians, and researchers, known as the ALGOL 60 committee. This committee included influential figures such as John Backus, Peter Naur, Alan Perlis, and Heinz Rutishauser, among others.</p><p>While it is not clear which specific member of the committee proposed the use of the semicolon as a statement separator, the decision was likely a result of collaborative discussions and consensus among the members. The choice of the semicolon in ALGOL 60 set a precedent that influenced many subsequent programming languages, solidifying its role as a common convention in programming syntax.</p><h3>1. The ALGOL Family and Its Influence</h3><p>The ALGOL (ALGOrithmic Language) family consists of a series of high-level programming languages developed between the late 1950s and early 1960s. These languages were designed for expressing algorithms and scientific computing, with an emphasis on mathematical notation and structured programming. The ALGOL family played a critical role in shaping the syntax and design principles of many subsequent programming languages. Among the various versions of ALGOL, ALGOL 60 stands out as one of the most influential, introducing the semicolon as a statement separator.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*trdymIC_1inIOGLCHy0zkQ.png" /><figcaption>ALGOL 60</figcaption></figure><h4>1.1 The ALGOL 60 Committee: Key Figures and Collaborations</h4><p>The development of ALGOL 60 was overseen by an international committee of computer scientists, mathematicians, and researchers. The committee included notable figures such as:</p><ul><li><strong>John Backus</strong>: An American computer scientist known for his work on the Fortran programming language and the development of the Backus-Naur Form (BNF), a notation used for describing the syntax of programming languages.</li><li><strong>Peter Naur</strong>: A Danish computer scientist who contributed significantly to the design of ALGOL 60 and the development of the BNF. He is often considered the “father” of ALGOL 60.</li><li><strong>Alan Perlis</strong>: An American computer scientist who was involved in the development of early programming languages and played an essential role in the design of ALGOL 60.</li><li><strong>Heinz Rutishauser</strong>: A Swiss mathematician and computer scientist who worked on developing early programming languages and contributed to the design of ALGOL 60.</li></ul><p>The committee worked together to develop a language that could express complex algorithms and mathematical concepts in a clear, structured manner. Their collaboration laid the groundwork for many of the design principles that would later influence the development of other programming languages.</p><h4>1.2 The Role of the Semicolon in ALGOL 60</h4><p>ALGOL 60 introduced the semicolon as a statement separator, which proved to be a significant milestone in the development of programming languages. The use of the semicolon as a separator offered several advantages:</p><ul><li><strong>Improved readability</strong>: Semicolons clearly marked the end of one statement and the beginning of another, making it easier for programmers to follow the flow of the code.</li><li><strong>Simplified parsing and compilation</strong>: The use of semicolons as separators made it easier for compilers to identify and process individual statements, resulting in more efficient and accurate compilation.</li><li><strong>Familiarity for mathematicians and scientists</strong>: The choice of the semicolon as a statement separator provided a sense of familiarity for mathematicians and scientists, as semicolons are often used as separators in mathematical notation.</li></ul><h4>1.3 The ALGOL 60 Development Process</h4><p>During the development of ALGOL 60, the committee members faced various challenges and engaged in numerous discussions to arrive at the final design of the language. Some interesting anecdotes from this process include:</p><ul><li>The choice of the semicolon as a statement separator was not immediate. The committee considered other symbols, such as the comma, which was used in Fortran. However, after much deliberation, they settled on the semicolon due to its clear visual distinction and familiarity in mathematical notation.</li><li>The development of ALGOL 60 was a highly collaborative process, with committee members often engaging in heated debates about language features and design principles. One such debate centered around the choice of block structure and control statements. The final design of ALGOL 60 incorporated a novel and powerful block structure that influenced the design of subsequent languages.</li><li>During the ALGOL 60 committee meetings, members frequently used blackboards to illustrate their ideas, as computer terminals were not yet widely available. This practice led to the development of a clear, human-readable syntax that was more focused on expressing concepts and algorithms than on machine-level details.</li><li>Peter Naur played a pivotal role in documenting the ALGOL 60 language specification. His attention to detail and dedication to clarity were instrumental in producing a well-defined and consistent language description, which became a model for future programming language specifications.</li></ul><h3>2. The Semicolon in Early Programming Languages</h3><p>Not all early programming languages adopted the semicolon. Languages such as Fortran, COBOL, and LISP, choose alternative methods. the evolution of statement separators in languages like CPL, BCPL, and B, and the eventual standardisation of the semicolon in the C programming language.</p><h4>2.1. Fortran</h4><p>Fortran, one of the earliest high-level programming languages, did not use the semicolon as a statement separator. Instead, each statement was placed on a separate line, and line breaks served as statement separators. This approach made the code easily readable and allowed for straightforward parsing by compilers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wp1HNb408jyfkF3rRxDVCg.png" /><figcaption>Fortran</figcaption></figure><h4>2.2. COBOL</h4><p>In COBOL, periods (or full stops) were used to separate and terminate statements. COBOL’s syntax was designed to be more English-like and verbose, and the use of periods contributed to the language’s overall readability and ease of use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cO9jWmL3cQXcIwJGi3zVqw.png" /><figcaption>COBOL</figcaption></figure><h4>2.3. LISP</h4><p>LISP, a language designed primarily for symbolic computation and manipulation, did not require a statement separator like the semicolon. Instead, LISP relied on parentheses to indicate structure and nesting in the code. The use of parentheses provided a unique and expressive syntax that allowed for flexible and powerful programming constructs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MDdwnVEkjRCvIFWP0XjrRA.png" /><figcaption>LISP</figcaption></figure><h3>3. CPL, BCPL, and B: The Evolution of Statement Separators</h3><h4>3.1. CPL (Combined Programming Language)</h4><p>CPL, a programming language developed in the 1960s, was influenced by the ALGOL family and used the semicolon as a statement separator. CPL was designed to be a general-purpose language and aimed to improve upon the features of ALGOL 60.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9krHzFR9Vzb9Y5hmo2kB9g.png" /><figcaption>CLP</figcaption></figure><h4>3.2. B Programming Language</h4><p>The B programming language, developed by Ken Thompson and Dennis Ritchie, was inspired by BCPL and also used the semicolon as a statement separator. B was designed as a systems programming language for the DEC PDP-7 computer, and its development laid the groundwork for the creation of the C programming language.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DyiGMgQljZVSRwLVqQuWEA.png" /><figcaption>B</figcaption></figure><h3>4. The Birth of C and the Standardisation of the Semicolon</h3><p>The semicolon has become a pervasive syntactic element in many modern programming languages, thanks to its adoption in influential languages like C.</p><p>Dennis Ritchie, one of the developers of the B programming language, created the C programming language in the early 1970s. C was designed as a systems programming language for the UNIX operating system and was heavily influenced by the B language. C retained the use of the semicolon as a statement separator, which contributed to the language’s readability and ease of parsing.</p><p>The C programming language quickly gained popularity due to its efficiency, portability, and powerful features. Its widespread adoption led to the standardisation of the semicolon as a statement separator in many subsequent programming languages, such as C++.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f73ZotOUbZa4Mp7bpRsl2Q.png" /><figcaption>C</figcaption></figure><h4>4.1 C++: Expanding the C Language with Object-Oriented Features</h4><p>C++, developed by Bjarne Stroustrup in the early 1980s, extended the C programming language with object-oriented features. C++ retained the use of the semicolon as a statement separator, as it was designed to be backward compatible with C. The semicolon continues to play a crucial role in maintaining code readability and structure in C++ programs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5anep25Vp8rwcUssDwEzfQ.png" /><figcaption>C++</figcaption></figure><h4>4.2 Java: A Platform-Independent Language for the World Wide Web</h4><p>Java, created by James Gosling and his team at Sun Microsystems in the mid-1990s, was designed as a platform-independent language for the emerging World Wide Web. Java adopted the semicolon as a statement terminator, a decision influenced by its C and C++ heritage. The semicolon helps define Java’s syntax and plays an essential role in separating statements and maintaining code readability.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hl2_PwkX1zCe8wya8MpHpA.png" /><figcaption>Java</figcaption></figure><h4>4.3 JavaScript: A Scripting Language for the Modern Web</h4><p>Despite its name, JavaScript is not directly related to Java. However, its syntax was influenced by both Java and C. Developed by Brendan Eich in 1995, JavaScript is a scripting language for the web that uses the semicolon as a statement terminator. While the use of semicolons in JavaScript is technically optional, many developers and coding style guides advocate for their consistent use to ensure code readability and reduce potential errors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N2McrZJQWFO-eJN-4w-vIA.png" /><figcaption>JavaScript</figcaption></figure><h4>4.4 Other Languages Influenced by the Semicolon</h4><p>In addition to the languages mentioned above, the semicolon has influenced the syntax of numerous other modern programming languages. Some examples include:</p><ul><li>PHP: A server-side scripting language for web development, PHP uses the semicolon as a statement terminator. Its syntax is influenced by C, C++, and Java.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G0NoZLyJ3HesIMVXYtea4w.png" /><figcaption>PHP</figcaption></figure><ul><li>Swift: Developed by Apple, Swift is a programming language for iOS, macOS, watchOS, and tvOS app development. Swift adopts the semicolon as a statement terminator, although its use is optional in many cases.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uFZ7BuojB-sGZXLxXGWWsA.png" /><figcaption>Swift</figcaption></figure><ul><li>Rust: A systems programming language with a focus on safety and performance, Rust employs the semicolon as a statement terminator. Its syntax is influenced by C and C++.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5M1z5l7ciwI6t61qm1sOYA.png" /><figcaption>Rust</figcaption></figure><h3>Conclusion</h3><p>The semicolon has been an integral part of programming languages since the era of ALGOL 60, and its influence has extended to many modern languages, including C, C++, Java, JavaScript, and others. Its role as a statement separator has contributed to the readability, organisation, and clarity of code across generations of programming languages. While some languages, such as Python and Swift, have reduced the reliance on semicolons, they continue to play an essential role in numerous other languages.</p><p>The collaborative efforts of the ALGOL 60 committee and the subsequent work of computer scientists, mathematicians, and researchers have ensured the semicolon’s enduring presence in the syntax of programming languages. As programming languages continue to evolve and new paradigms emerge, the semicolon’s role may shift and adapt. However, its influence on the design and structure of programming languages cannot be overstated, and it remains a symbol of the importance of clear, readable code in the world of software development.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a00165ae331e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Babashka To Transform Lines of Text in a File]]></title>
            <link>https://medium.com/@kerronp/using-babashka-to-transform-lines-of-text-in-a-file-3c923a1f6326?source=rss-ed0c554f169f------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c923a1f6326</guid>
            <category><![CDATA[shell]]></category>
            <category><![CDATA[clojure]]></category>
            <category><![CDATA[scripting]]></category>
            <category><![CDATA[bash]]></category>
            <category><![CDATA[babashka]]></category>
            <dc:creator><![CDATA[Kerron Parchment]]></dc:creator>
            <pubDate>Sun, 02 Apr 2023 14:02:30 GMT</pubDate>
            <atom:updated>2023-04-02T14:02:30.706Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Oq8kkCvf15IKJFCqhpCqw.png" /></figure><p>Sometimes, we need to transform lines of text in a file to a different format. This can be a tedious task if done manually, especially if we have a large number of lines to transform. In this article, we’ll explore how to use Babashka to automate this task and transform lines of text in a file to a different format.</p><h3>What is Babashka?</h3><p><a href="https://github.com/babashka/babashka">Babashka</a> is a Clojure scripting environment that allows you to run Clojure code without having to set up a project or compile any code. Babashka comes with a set of built-in functions that make it easy to perform common tasks like reading files, working with JSON and XML data, and more. It is cross-platform, so you can use it on Windows, macOS, and Linux systems without any issues.</p><h3>Problem Statement</h3><p>Suppose we have a file containing lines of text in the following format:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k2zsn_GQ9x300HVPGQAw_A.png" /><figcaption>String to parse</figcaption></figure><p>We want to transform each line to the following format:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MGIpyFUW_oiiSLQ9xy2l4g.png" /><figcaption>Expected result after parsing</figcaption></figure><h3>Solution</h3><p>To solve this problem, we can use Babashka to read the input file, transform each line to the desired format, and write the transformed lines to an output file. Here’s the complete solution:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xP_j7VVvCvui8ExToJ8vqA.png" /><figcaption>Solution code</figcaption></figure><p>Let’s go through each part of the solution step by step in term of how the processing happens:</p><h4>Shebang</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TQ-FOnNL6aFZIR1PygKahQ.png" /></figure><p>This line tells the operating system to use the bb interpreter located in the user’s environment to execute the script.</p><h4>Libraries</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GkV9ZthyD3tZsjkhMhuvRw.png" /></figure><p>This block imports two libraries, clojure.string and clojure.java.io, which are used later in the script. The :as keyword is used to create aliases for the imported libraries to make it easier to reference them later.</p><h4>Reading the Input File</h4><p>The first step is to read the input file containing the lines of text that need to be transformed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PQcmJAtcVlgqboaSGCiLFA.png" /><figcaption>Code for reading the input file</figcaption></figure><p>This code uses the with-open macro to open a reader and a writer for our input-file and output-file, respectively. The io/reader and io/writer functions are used to create the reader and writer objects, which are then bound to the reader and writer variables using destructuring.</p><p>The with-open macro also ensures that the reader and writer objects are properly closed when the code inside the macro finishes executing, even if an exception is thrown. This helps to avoid resource leaks and ensures that the files are closed and any associated system resources are released.</p><h4>Transforming Each Line</h4><p>For each line of text in the input file, we need to transform it to the desired output format. We can use the clojure.string namespace and the replace function to replace the parts of the line that need to be modified.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uEAFw0zJswkUaqve1pWYog.png" /><figcaption>Code for transforming each line</figcaption></figure><p>The transform-line function takes a line of text as input, and uses the str/replace function to replace the first capture group ((\w+)) with | $1 |, the second capture group ((\d+)) with | $2 |, and the third capture group ((.+)) with | $3 |.</p><h4>Writing Transformed Lines to Output File</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7m7J5SeSrfhnKVmnWB8jbg.png" /><figcaption>Code for writing transformed lines to output file</figcaption></figure><p>.write is a method in Java and Clojure that is used to write a sequence of characters to a file or other output stream. In this case, it is being used to write the transformed line to an output file. The str function is used to convert the transformed line to a string before it is written to the file. The \n character is added to the end of the string to ensure that each line is written on a separate line in the output file.</p><p>writer is a variable that represents the output file. The writer variable is passed as an argument to the .write method to specify the output stream to which the transformed lines should be written.</p><p>The doseq function is being used to iterate over each line in the input file. For each line, the transform-line function is called to transform the line into a new format. The transformed line is then printed to the console using println and written to the output file using .write and writer.</p><p>line-seq is a lazy function, which means that it does not read the entire input source into memory at once. Instead, it reads each line of the input source as needed, and returns a sequence of lines that can be processed one by one. This can be useful for working with large input sources, as it allows you to process the input data incrementally and without consuming excessive amounts of memory.</p><h3>Running the Solution</h3><p>To run the solution, save the script to a file (e.g., transform-lines.bb) and make it executable by running the following command in your terminal:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U7fW3kAdQomhbAUfc1MXTg.png" /><figcaption>Command to make script file executable</figcaption></figure><p>Then, run the script by specifying the input and output file names as arguments:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P-i8KKoidMkUNILG_VlavA.png" /><figcaption>Command to run script</figcaption></figure><p>This will read the lines from input-file.txt, transform them to the desired format, and write the transformed lines to output-file.txt.</p><h3>Result</h3><p>Here is a 3 line example of an input file and the output file from running the script:</p><p><strong>Input</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pnulfX5QmFJrXGZsJEEfHA.png" /><figcaption>input-file.txt</figcaption></figure><p><strong>Output</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZE-SXqw2BPAtPcw7-543RQ.png" /><figcaption>output-file.txt</figcaption></figure><h3>Conclusion</h3><p>In this article, we explored how to use Babashka to transform lines of text in a file to a different format. Babashka provides a simple and concise way to perform this task, allowing you to focus on the transformation logic rather than the boilerplate code for reading and writing files.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c923a1f6326" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sorting Words Based on Embedded Numbers: Examples in Haskell, Python, JavaScript, Clojure and Rust]]></title>
            <link>https://medium.com/@kerronp/sorting-words-based-on-embedded-numbers-examples-in-haskell-python-javascript-clojure-and-rust-f4a2f51bb319?source=rss-ed0c554f169f------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4a2f51bb319</guid>
            <category><![CDATA[clojure]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[rust-programming-language]]></category>
            <category><![CDATA[haskell]]></category>
            <dc:creator><![CDATA[Kerron Parchment]]></dc:creator>
            <pubDate>Sun, 26 Mar 2023 15:01:48 GMT</pubDate>
            <atom:updated>2023-03-26T15:01:48.676Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0KMcuAGxe8hZi0DVUIIEGw.png" /><figcaption>Programming Language Logos</figcaption></figure><p>In this article, we will explore a problem where we have to sort a given string of words based on embedded numbers within each word. We will provide a solution for this problem in five different programming languages: Haskell, Python, JavaScript, Ruby, and Rust. We will also discuss the intuition behind each solution, and in the conclusion, determine which one is the shortest.</p><p><strong>Problem Statement</strong>: Given an input string, sort the words based on the numbers found within each word. The input string will contain only single-digit numbers. For example, if the input string is &quot;is2 Thi1s T4est 3a&quot;, the output should be &quot;Thi1s is2 3a T4est&quot;. The problem can be found <a href="https://www.codewars.com/kata/55c45be3b2079eccff00010f">here</a> on Codewars.</p><h3>Haskell Example</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pYGKyMPSxeamH6b-J5NQBQ.png" /><figcaption>Example in Haskell</figcaption></figure><p>In Haskell, the yourOrderPlease function takes a string input and sorts the words based on the first digit found in each word. The function uses words, sortOn, find, isDigit, and unwords to achieve this.</p><h3>Python Example</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c5ABdnvhjS-9k4tLl0_6Ng.png" /><figcaption>Example in Python</figcaption></figure><p>In Python, the your_order_please function splits the input string into words, sorts them based on the first digit found in each word using the sorted function and a custom key, and then joins the sorted words into a single string.</p><h3>JavaScript Example</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QeaB6jztQz_JVKjwN8d7zQ.png" /><figcaption>Example in JavaScript</figcaption></figure><p>In JavaScript, the yourOrderPlease function splits the input string into an array of words, sorts them based on the first digit found in each word using the sort function with a custom comparator, and then joins the sorted words into a single string.</p><h3>Clojure Example</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PGDVLZfbD8rFnV0IVUJPeQ.png" /><figcaption>Example in Clojure</figcaption></figure><p>This Clojure code uses str/split to split the input string into a sequence of words, sort-by with a lambda function to find the first digit in each word and sort the sequence based on the digits, and str/join to combine the sorted sequence back into a single string.</p><h3>Rust Example</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vWsLnx94Bp-T1Y8P1lNv8Q.png" /><figcaption>Example in Rust</figcaption></figure><p>In this Rust code, the your_order_please function takes a &amp;str (string slice) as input and returns a String. The function uses split_whitespace, collect, sort_by_key, chars, find, unwrap, and join to achieve the desired functionality.</p><h3>Conclusion</h3><p>In this article, we have explored how to implement the your_order_please function in five different programming languages: Haskell, Python, JavaScript, Clojure, and Rust. Each language offers a unique approach to solving the problem, while the underlying logic remains consistent: split the input string into words, sort the words based on the first digit found within each word, and join the sorted words back into a single string.</p><p>When comparing the different implementations, Haskell stands out as the shortest and most concise solution.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4a2f51bb319" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Demystifying Function Calls: The 5 Parameter-Passing Mechanisms in Programming Languages With…]]></title>
            <link>https://medium.com/@kerronp/demystifying-function-calls-the-5-parameter-passing-mechanisms-in-programming-languages-with-fbd6ed805c5b?source=rss-ed0c554f169f------2</link>
            <guid isPermaLink="false">https://medium.com/p/fbd6ed805c5b</guid>
            <category><![CDATA[haskell]]></category>
            <category><![CDATA[c-programming]]></category>
            <category><![CDATA[scala]]></category>
            <category><![CDATA[cpp]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Kerron Parchment]]></dc:creator>
            <pubDate>Tue, 21 Mar 2023 16:09:18 GMT</pubDate>
            <atom:updated>2023-03-21T16:09:18.849Z</atom:updated>
            <content:encoded><![CDATA[<h3>Demystifying Function Calls: The 5 Parameter-Passing Mechanisms in Programming Languages With Analogies</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yfD9Ko62U08t4NVd" /><figcaption>Photo by <a href="https://unsplash.com/@jstrippa?utm_source=medium&amp;utm_medium=referral">James Harrison</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Parameter-passing mechanisms define how arguments are passed from a calling function to a called function in programming languages. Understanding these mechanisms is crucial for developers to write efficient and predictable code. In this article, we will explore the five main parameter-passing mechanisms with examples in appropriate programming languages and compare their characteristics.</p><h3>1. Call-by-value</h3><p>In call-by-value, the value of the argument is passed to the called function, and any changes made to the parameter inside the function do not affect the original variable. This is because the called function receives a copy of the argument value. Call-by-value is widely used in languages like C, Java, and most functional programming languages.</p><p><strong>Analogy — The Photocopy: </strong>Think of call-by-value as handing someone a photocopy of a document. Any changes they make to the photocopy don’t affect the original document. This is how call-by-value works in programming languages like C and Java: the called function receives a copy of the argument value, so any changes made to the parameter inside the function do not affect the original variable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*GCmeB6TL20TyO3QxJftV4Q.png" /><figcaption><em>Example in C</em></figcaption></figure><p>Pros:</p><ul><li>Prevents unintentional modifications to the original variable.</li><li>Simplifies reasoning about the function behaviour.</li></ul><p>Cons:</p><ul><li>May lead to performance overhead due to copying large data structures.</li></ul><h3>2. Call-by-reference</h3><p>Call-by-reference passes the memory address of the argument to the called function. This allows the function to modify the original variable directly. Languages like C++, Fortran, and C# support call-by-reference. In C#, the ref keyword is used to explicitly indicate call-by-reference.</p><p><strong>Analogy — The Shared Book:</strong> Call-by-reference can be thought of as giving someone access to your shared book with notes. Any notes they take will be visible to both of you, as you both have access to the same book. In programming languages like C++ and C#, the called function has access to the memory address of the argument, allowing it to modify the original variable directly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/956/1*LpI3TJ5WtRPJ0mZ8j2wMXg.png" /><figcaption>Example in C++</figcaption></figure><p>Pros:</p><ul><li>Efficient when working with large data structures.</li><li>Allows for multiple return values through function parameters.</li></ul><p>Cons:</p><ul><li>Can lead to unintended side effects due to direct modification of the original variable.</li></ul><h3>3. Call-by-name</h3><p>Call-by-name is a mechanism where the expression passed as a parameter is substituted directly into the function body. It is a rare mechanism in modern programming languages but is supported by languages like Scala with the =&gt; (arrow) notation. Call-by-name enables lazy evaluation, which means that the expression is only evaluated when it is actually used inside the function.</p><p><strong>Analogy — The Recipe</strong>: Call-by-name can be compared to a recipe. Instead of passing the prepared dish (value) to someone, you pass the recipe (expression). The recipe is then “cooked” (evaluated) each time it’s needed in the function. Languages like Scala support call-by-name, enabling lazy evaluation where expressions are evaluated only when used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KzQdAr_ii3pYoe9S_0M4rg.png" /><figcaption>Example in Scala</figcaption></figure><p>Pros:</p><ul><li>Can improve performance by avoiding unnecessary evaluations.</li><li>Enables interesting language constructs and control structures.</li></ul><p>Cons:</p><ul><li>Might lead to code that is harder to reason about due to multiple evaluations of the same expression.</li></ul><h3>4. Call-by-sharing (Call-by-object)</h3><p>Call-by-sharing, also known as call-by-object or call-by-object-sharing, is a mechanism where a reference to the object is passed to the function. However, the reference itself is passed by value. This allows the function to modify the original object but not the reference. This mechanism is used in languages like Python, JavaScript, and Ruby.</p><p><strong>Analogy — The House Key</strong>: Call-by-sharing is like giving someone a copy of your house key. They can enter your house and rearrange the furniture (modify object properties) but cannot change the house itself (the reference). Languages like Python, JavaScript, and Ruby use call-by-sharing, where the reference to the object is passed to the function but the reference itself is passed by value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*oGGxB0K_AL-iTAoRm4HvxA.png" /><figcaption>Example in Python</figcaption></figure><p>Pros:</p><ul><li>Efficient when working with large data structures.</li><li>Provides a balance between call-by-value and call-by-reference in terms of safety and performance.</li></ul><p>Cons:</p><ul><li>Can still lead to unintended side effects due to modification of the original object.</li></ul><h3>5. Call-by-need (Lazy evaluation)</h3><p>Call-by-need, also known as lazy evaluation, is a mechanism where function arguments are not evaluated until they are actually needed (used) inside the function. This can be beneficial for performance in certain situations, as it avoids unnecessary computation. Haskell is an example of a language that employs call-by-need evaluation.</p><p><strong>Analogy — The On-Demand Chef </strong>: Call-by-need is like having an on-demand chef at your disposal. They prepare and cook a dish only when you’re ready to eat it. In programming languages like Haskell, function arguments are not evaluated until they are actually needed (used) inside the function. This lazy evaluation can be beneficial for performance, as it avoids unnecessary computation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6o6uyfcbI3Wj3RD7mi-iTQ.png" /><figcaption>Example in Haskell</figcaption></figure><p>Pros:</p><ul><li>Can improve performance by avoiding unnecessary evaluations.</li><li>Supports infinite data structures and other advanced constructs.</li></ul><p>Cons:</p><ul><li>May lead to increased memory usage due to unevaluated expressions.</li></ul><h3>Conclusion</h3><p>Understanding the various parameter-passing mechanisms used in programming languages helps developers write more efficient and predictable code. By exploring these concepts through everyday analogies, you can grasp the key differences and characteristics more intuitively. As you continue your programming journey, keep these analogies in mind to help you make more informed decisions when designing and implementing your software.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fbd6ed805c5b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What The Script: 5 languages for frontend development]]></title>
            <link>https://medium.com/@kerronp/what-the-script-5-languages-for-frontend-development-da6c83154d97?source=rss-ed0c554f169f------2</link>
            <guid isPermaLink="false">https://medium.com/p/da6c83154d97</guid>
            <category><![CDATA[reasonml]]></category>
            <category><![CDATA[clojurescript]]></category>
            <category><![CDATA[elm-lang]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[purescript]]></category>
            <dc:creator><![CDATA[Kerron Parchment]]></dc:creator>
            <pubDate>Mon, 13 Mar 2023 01:14:28 GMT</pubDate>
            <atom:updated>2023-03-13T01:16:07.400Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2WH81sWYll4gHFgQSEIdTw.jpeg" /><figcaption>Logos of frontend programming languages</figcaption></figure><p>Frontend development is an exciting field that involves creating user interfaces that are both beautiful and functional. Over the years, several programming languages have emerged that allow developers to build powerful, interactive web applications. In this article, we’ll take a look at five frontend languages — TypeScript, PureScript, Elm, ReasonML, and ClojureScript — and compare their features, syntax, and use cases.</p><p>Let’s start by looking at TypeScript.</p><h3>TypeScript</h3><p><strong>Creator</strong>: Microsoft, <strong>Created</strong>: 2012.</p><p>TypeScript is a superset of JavaScript that adds optional static typing and other features to make JavaScript code more scalable and maintainable. TypeScript supports JSX syntax, which allows developers to write HTML-like structures in JavaScript.</p><p>Here’s an example of how to use JSX syntax in TypeScript to create a simple “Hello, World!” application:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nhZ7aXjiWhFGqOn631Kghg.png" /><figcaption>TypeScript</figcaption></figure><p>In this example, we import the React and ReactDOM libraries and define a functional component called App that returns an h1 element with the text Hello, World!. We then use ReactDOM.render() to render the App component to the DOM, using the root element as the target.</p><p>TypeScript is a superset of JavaScript, so its architecture design is very similar to that of JavaScript. It allows for a variety of architecture patterns, such as the traditional Model-View-Controller (MVC) and Model-View-ViewModel (MVVM) patterns. TypeScript’s type system helps prevent errors and makes it easier to reason about the flow of data through the application.</p><p>Next, let’s take a look at PureScript</p><h3>PureScript</h3><p><strong>Creator</strong>: Phil Freeman, <strong>Created</strong>: 2013</p><p>PureScript is a strongly-typed, purely functional programming language that compiles to JavaScript. It aims to provide a clean, expressive syntax and type system that make it easy to write scalable, maintainable code. Like TypeScript, PureScript supports JSX syntax.</p><p>Here’s an example of how to use JSX syntax in PureScript to create a simple “Hello, World!” application:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nZoCAgoEX9p1H7bpQc7AFg.png" /><figcaption>PureScript</figcaption></figure><p>In this example, we define a PureScript component called component that uses the React library to create an h1 element with the text Hello, World!. We then use the ReactDOM.renderToDOM() function to render the component to the DOM, using the root element as the target.</p><p>PureScript’s architecture design is typically based on functional programming concepts such as immutability and pure functions. PureScript applications often use a pattern called the Elm Architecture, which consists of three main components: Model, Update, and View. The Model represents the current state of the application, the Update function handles state transitions, and the View function renders the current state of the application.</p><p>Now, let’s move on to Elm.</p><h3>Elm</h3><p><strong>Creator</strong>: Evan Czaplicki, <strong>Created</strong>: 2012.</p><p>Elm is a purely functional programming language that compiles to JavaScript and is designed for building scalable, maintainable web applications. It is specifically designed for building frontend applicationsI, providing a strong type system and an expressive syntax that make it easy to write safe, error-free code. Elm uses a different syntax than TypeScript and PureScript to create HTML-like structures, but the result is similar.</p><p>Here’s an example of how to create a simple “Hello, World!” application in Elm:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*BaaJKd3xVgmZlOvocT0PZQ.png" /><figcaption>Elm</figcaption></figure><p>In this example, we define an Elm module called Main that imports the Html library and uses it to create an h1 element with the text Hello, World!. We then use the Html.program() function to render the component to the DOM, using the root element as the target.</p><p>The Elm architecture design is heavily influenced by the Model-View-Update (MVU) pattern, and influences the architecture design used in PureScript. The Model represents the current state of the application, the Update function handles state transitions, and the View function renders the current state of the application. Elm’s compiler enforces this pattern, making it easier to write predictable, maintainable code.</p><p>Now, let’s take a look at ReasonML.</p><h3>ReasonML</h3><p><strong>Creator</strong>: Jordan Walke, <strong>Created</strong>: in 2017.</p><p>ReasonML is a syntax and toolchain for OCaml that aims to bring the benefits of functional programming to web development. It provides a type-safe, expressive syntax that compiles to efficient JavaScript code. ReasonML uses a syntax that is similar to JavaScript and JSX, making it easy for developers to transition from those languages.</p><p>Here’s an example of how to use ReasonML to create a simple “Hello, World!” application using JSX syntax:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*gD8SXFScaH5TLC9bcu1nrw.png" /><figcaption>ReasonML</figcaption></figure><p>In this example, we define a stateless ReasonReact component called App that returns an h1 element with the text Hello, World!. We then use the ReactDOMRe.renderToElementWithId() function to render the component to the DOM, using the root element as the target.</p><p>ReasonML’s architecture design is similar to that of OCaml, which is based on the functional programming paradigm. ReasonML applications often use the Redux pattern, which separates state and UI concerns. The state of the application is managed by a single store, and changes to the state are handled by reducers. The UI is defined by React components, which receive state and dispatch functions as props.</p><p>Jordan Walke, is also the creator of React.</p><p>Finally, let’s take a look at ClojureScript.</p><h3>ClojureScript</h3><p><strong>Creator</strong>: Rich Hickey, <strong>Created</strong>: 2011.</p><p>ClojureScript is a dialect of the Clojure programming language that compiles to JavaScript. It aims to provide a functional, immutable programming model that makes it easy to reason about complex applications. ClojureScript uses a different syntax than the other languages we’ve looked at, but it is designed to be easy to read and write.</p><p>Here’s an example of how to use ClojureScript to create a simple “Hello, World!” application:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*XancRc5b9zstnJBomD5QeA.png" /><figcaption>ClojureScript</figcaption></figure><p>In this example, we define a Reagent component called app that returns an h1 element with the text Hello, World!. We then use the reagent.core/render-component function to render the component to the DOM, using the root element as the target.</p><p>ClojureScript’s architecture design is based on the functional programming paradigm and is heavily influenced by the React library. ClojureScript applications often use the Reagent library, which provides a simple way to create React components. Reagent components are defined as functions that take in state and return React elements. ClojureScript applications often use the Reagent pattern, which separates state and UI concerns similar to the Redux pattern used in ReasonML.</p><h3>Conclusion</h3><p>In conclusion, each of these five languages has its own strengths and weaknesses, and choosing the right one depends on your specific needs and preferences. Whether you prefer a statically typed language like TypeScript or a functional language like Elm or ReasonML, there is a frontend language that can help you build the web application of your dreams.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da6c83154d97" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Note Taking Workflow]]></title>
            <link>https://medium.com/@kerronp/my-note-taking-workflow-1f45784ff4e1?source=rss-ed0c554f169f------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f45784ff4e1</guid>
            <category><![CDATA[obsidian]]></category>
            <category><![CDATA[productivity]]></category>
            <dc:creator><![CDATA[Kerron Parchment]]></dc:creator>
            <pubDate>Tue, 09 Aug 2022 20:58:41 GMT</pubDate>
            <atom:updated>2022-08-10T08:10:58.095Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*ynFvze8a3bUetpTnSkNphQ.png" /></figure><p>In this article I go over the methods I use to consume content. There’s a lot more nuances that go into it, but this article gives a high level overview and focuses on the main points.</p><p>I consume content mostly through books, podcasts, videos, websites (blogs) and research articles in this order. All of this information goes into my <a href="https://obsidian.md/">Obsidian</a>. Obsidian is a note taking application similar to <a href="https://bear.app/">bear</a>, <a href="https://roamresearch.com/">roam</a>, and <a href="https://evernote.com/">evernote</a>, but is far superior in my humble opinion.</p><p>The medium I consume the most are books. I prefer reading books over everything else as I feel the content I get is superior to most of the other mediums, and it is also one of the easiest medium for me to consume. Though I enjoy the tactile sensation of reading a physical book, I try to consume as much as I can through the <a href="https://play.google.com/store/apps/details?id=com.amazon.kindle&amp;hl=en_GB&amp;gl=US">kindle app</a>. This is because I can quickly read a page or two irrespective of where I am, make notes, and sync this up with my Obsidian.</p><p>I also get great content from reading research articles. This content can be superior to books, but I find it takes much longer for me to consume (topic dependent), as the material is generally quite dense. That said, I find it to be knowledge expansive and I enjoy it for this very reason. I use <a href="https://www.zotero.org/">Zotero</a> and the <a href="https://play.google.com/store/apps/details?id=org.readera&amp;hl=en_GB&amp;gl=US">readEra</a> android app to consume this kind of content. Zotero helps me highlight, annotate and export content into Obsidian, which I can then expand on in writing, and also make references back to these highlights in Zotero from within other notes in Obsidian.</p><p>Most of the podcasts I listen to are around Software Engineer. This means the content can get very technical, and when listening to podcasts I find myself rewinding and making notes all the time. For this I find <a href="https://www.snipd.com/">snipd</a> to be an awesome app that takes care of all the burdensome activities of this for me. It’s absolutely brilliant.</p><p>For videos the obvious medium here is YouTube. I often take notes manually by acknowledging the time in the video when making related notes. I then use this as reference with the video link within Obsidian. Currently I am using <a href="https://askify.video/">Askify</a> to do this, but I am still looking for a nice extension to help me make great YouTube references.</p><p>I use <a href="https://raindrop.io/">Raindrop.io</a> when consuming content on blogs and miscellaneous websites. I have completely moved away from storing my bookmarks in my browsers and storing them directly in Raindrop.io instead. Raindrop.io makes for easy highlighting, annotating, consumption, tagging, etc. This allows me to very easily save each thought as I read the article, and ultimately make better notes in Obsidian. Using Raindrop.io also means I can reference these annotation much easier in the future. I also have a shortcut in <a href="https://www.alfredapp.com/">Alfred</a> which allows me to search through these bookmarks with ease.</p><p>This was a high level overview of my note taking method as it currently stands. That said, these methods are bound to change as I grow and learn about new ways of note-taking.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f45784ff4e1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript Engine Optimisation; A Reason For Types.]]></title>
            <link>https://medium.com/@kerronp/javascript-engine-optimisation-a-reason-for-types-470530b5051e?source=rss-ed0c554f169f------2</link>
            <guid isPermaLink="false">https://medium.com/p/470530b5051e</guid>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Kerron Parchment]]></dc:creator>
            <pubDate>Sat, 04 Aug 2018 15:18:02 GMT</pubDate>
            <atom:updated>2018-08-04T15:18:02.352Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article I will look at a simple way to help optimise for JavaScript engine performance. To be clear I will not be looking at performance issues such latency, DOM manipulation, rendering, network latency, etc. These are all super important topics that warrant separate articles.</p><p>When you run JavaScript it is compiled by a JavaScript Engine. Traditionally, JavaScript code was translated to machine code using an interpreter. However, Javascript engines have evolved over the last two decades to run large and complex frameworks, to servers such as Node.js.</p><p>There are a few different JavaScript engines such as SpiderMonkey (Mozilla/Firefox), Chakra (Microsoft/Edge), V8 (Chrome, Node.js, Brave), JavaScriptCore (Safari). For IoT devices where memory is quite important, there are Javascript Engines such as JerryScript and DukTape.</p><p>Similarly to JavaScript, its engines follow the ECMAScript standard to implement and run your JavaScript code. This standard is governed by the TC39 Committee.</p><p><strong>Just In Time compilation (JIT).</strong></p><p>Modern JavaScript engines have at least two compilers, one of them being an optimising compiler.</p><p>Instead of compiling ahead of time and then running the code, modern JavaScript Engines mixes these two steps together. The engine runs the source code, compiles it just when it’s needed, collects information, and then uses this information to recompile the code.</p><p>Different engines do this in slightly different ways, but the basic concept is the same; JavaScriptCore for example has three compilers, two of which are optimisers.</p><p>This kind of compilation brings with it better optimisation and different ways to increases the performance of your code.</p><p>One such way is in marking a function as “hot”.</p><p>When the code is run, the compiler collects information about it such as how frequently it runs and the types that are being used. If the same lines of code are run a few times it will consider this code “warm”. If the code is run a lot it will considered it “hot”.</p><p>The optimising compiler uses the information it has gathered from running the function to speed up the process when it comes across this function again. It compiles assuming that it will see similar types as before to create optimised machine code.</p><p>The steps for this are:</p><ul><li>Compile,</li><li>Run a few times,</li><li>Optimise assuming certain conditions (i.e. types are the same),</li><li>Run optimised code (machine code),</li><li>If conditions change fallback to default behaviour.</li></ul><p><strong>Dynamically typed</strong></p><p>JavaScript however, is a dynamically typed language which means that variables can be created without specifying a type. Moreover, objects and variables can even be changed later to a totally different type.</p><pre>var example = 1; //no type declared; interpreted as type int<br>example = “Hello 1!” // now interpreted as type string</pre><p>Though this makes the language easier to program in, it also makes it harder for the engine to optimise and run your code. This is because there is no guarantee a function will receive the same types and therefore behave in the same way next time it runs.</p><p>Take this simple function for example:</p><pre>function find(obj) {<br>   return obj.x;<br>}</pre><p>Though it’s only 3 lines of code it is fairly complex for the JavaScript engine. It has to ask:</p><ul><li>does x exist?</li><li>is x a property of obj</li><li>is x a property of obj.prototype</li><li>if not, is x a part of the prototype chain?</li><li>where in memory is x?</li></ul><p>The compiler has to do a great deal of lookup just to find the x property. In addition, the order of the properties also make a difference to the compiler. Just because two objects have the same properties, it doesn’t mean that they are represented as the same type internally.</p><pre>load({x: 1, y:2});<br>load({x: 3, y:4});<br>load({x: 5, y:6});<br>load({x: 7, y:8});<br>//Can be optimised: object properties are all of the same type and structure.</pre><p>If for example you do not pass a property (in this case <strong><em>y</em></strong>) the engine will de-optimise this function as the object type is no longer consistent and is not represented as the same type internally.</p><pre>load({x: 1,}); //function is de-optimised</pre><p>To help the JavaScript compiler optimise your code it’s good practice to always use the same type of object. For example, if your objects represent the same thing (and it doesn’t make your code unreadable), you can make the engine know it’s the same type.</p><pre>load({x: 1, y:2});<br>load({x: 3, y: undefined}); //Can be optimised: y is passed undefined instead of omission</pre><p>This way the compiler will consider this as one object type, optimise the code, and later only have to do one comparison check.</p><p>If the code is optimised but types later change, there will be a performance drop when the engine has to de-optimise the code back to its default behaviour. This process is called de-optimisation or bailing out. It also ends up being slower than just executing the baseline compiled version of your code.</p><p>Most modern engines have added limits to break out of these optimisation/de-optimisation cycles when they happen. After a certain number of cycles it will stop trying to optimise the code.</p><p><strong>Conclusion</strong></p><p>Modern JavaScript engines run faster by monitoring the code as it’s running it and making certain assumptions. It then uses the information gathered to optimise the code, assuming it will see similar types as before. This can result in many-fold performance improvements for most Javascript applications.</p><p>Javascript is a dynamically typed language which makes this process hard to guarantee. The engine has to keep in memory both versions of the code (optimised, default) and de-optimise to the default code if types change. This causes a performance hit each time, but to avoid this, the engine will only try to optimise the code a certain number of times.</p><p>Writing javascript code that is statically types in nature and consistent in its execution will help the compiler to optimise your code to faster machine code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=470530b5051e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>