<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Dev Aces</title>
    <description>The latest articles on Forem by Dev Aces (@dev-aces).</description>
    <link>https://forem.com/dev-aces</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Forganization%2Fprofile_image%2F7525%2F89542507-b2a3-45f2-a1de-16ef6b804ef3.jpeg</url>
      <title>Forem: Dev Aces</title>
      <link>https://forem.com/dev-aces</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/dev-aces"/>
    <language>en</language>
    <item>
      <title>Programming language, don't make me think</title>
      <dc:creator>Artur Ampilogov</dc:creator>
      <pubDate>Fri, 15 Sep 2023 18:47:45 +0000</pubDate>
      <link>https://forem.com/dev-aces/programming-language-dont-make-me-think-5b3g</link>
      <guid>https://forem.com/dev-aces/programming-language-dont-make-me-think-5b3g</guid>
      <description>&lt;p&gt;Steve Krug published the famous book "Don't Make Me Think" in 2000 and gathered well-known ideas about Web usability. Authors of programming languages often lower the priority of simplicity or have to implement far-from-ideal solutions due to historical restrictions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft0nyvm82jhvnpv588max.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft0nyvm82jhvnpv588max.jpg" alt="Dont' make me think"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to measure complexity?
&lt;/h2&gt;

&lt;p&gt;Maintaining a product requires more reading code than writing. Hence, &lt;strong&gt;the code legibility is more important than its writing speed&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;One way to measure code complexity is to count &lt;strong&gt;how many terms a developer should hold in memory&lt;/strong&gt; to get a result.&lt;/p&gt;

&lt;p&gt;Another one is &lt;strong&gt;how much time it requires to understand the notion or to revise it&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Data structures and operations
&lt;/h2&gt;

&lt;p&gt;In short, programming is all about operations on data. To allocate memory for a 32-bit integer in statically typed languages, we can declare its type and assign a name to the memory block.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// C, C++, Java, C#
int x;

// Ada
X : Integer;

// TypeScript
let x: number;

// Rust
let x: i32;

// Go
var x int32
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is a way to infer a type by a compiler or even calculate the memory size and data structure at runtime. This approach is used in JavaScript, Python, and Ruby.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// JavaScript
let x;

// Python
x
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The untyped version requires additional time for a developer to figure out the argument structures. Consider the function declared in Python:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def display(person, age, payment)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Is &lt;code&gt;person&lt;/code&gt; an object, is &lt;code&gt;age&lt;/code&gt; a number, is &lt;code&gt;payment&lt;/code&gt; represented by a boolean, number, or money?&lt;/p&gt;

&lt;p&gt;Compare the same function written in C# that immediately gives answers about the structures:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void Display(string person, int age, decimal payment)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A statically typed language usage also has a vital benefit over a dynamic language - more error checks at compilation time. It is better to find errors at the earliest stage than make them to be discovered by users.&lt;/p&gt;

&lt;h3&gt;
  
  
  Assignment operator
&lt;/h3&gt;

&lt;p&gt;Most modern programming languages implement the assignment operator as the equal &lt;code&gt;=&lt;/code&gt; sign.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int x;
x = 1;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A fresh programming student trying to understand these statements may ask: "Is it possible to write &lt;code&gt;y = a*x^2 + b*x +c&lt;/code&gt; in code similar to the Math notation?" Although students   have been taught for many years that &lt;code&gt;=&lt;/code&gt; sign represents equation in Math, the answer is "no" for most of the programming languages.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faadtzzg9xtbaz7if3gcr.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faadtzzg9xtbaz7if3gcr.jpg" alt="Math meme"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In C, C++, Java, C#, PHP, Python, Ruby, Go, and Rust, the equal sign &lt;code&gt;=&lt;/code&gt; means an assignment. Pascal and Ada languages use the &lt;code&gt;:=&lt;/code&gt; sign, which at least is not a common Math symbol in schools (in Math, it is used as the equal by definition sign, in addition to &lt;code&gt;≡&lt;/code&gt;). &lt;/p&gt;

&lt;p&gt;But what does the assignment actually mean? The assignment operator in modern languages has two ideas behind it.&lt;/p&gt;

&lt;h4&gt;
  
  
  Value assignment
&lt;/h4&gt;

&lt;p&gt;The first one is called &lt;code&gt;value assignment&lt;/code&gt; and usually uses &lt;code&gt;deep copy&lt;/code&gt; of memory blocks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// C, C++, Java, C#
int x = 1; 
int y = x; // Deep copy of x to y
x = 2; // Change x
y; // y has the old value 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Reference assignment
&lt;/h4&gt;

&lt;p&gt;The second one is &lt;code&gt;reference assignment&lt;/code&gt;, which always uses the shared block of memory between variables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// C#
int[] array1 = { 1, 2, 3 }; // Array of 3 integers

int[] array2 = array1; // Reference assignment

array1[0] = 9; // Change the first element in array1
array1; // { 9, 2, 3 }
array2; // { 9, 2, 3 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Changes in &lt;code&gt;array1&lt;/code&gt; immediately affects &lt;code&gt;array2&lt;/code&gt; as both variables point to the same memory location.&lt;/p&gt;

&lt;p&gt;Java and C# oblige developers to remember what assignment behavior is associated with a structure. Moreover, C++ and C# allow to override the &lt;code&gt;=&lt;/code&gt; operator per object, and Java can achieve the same result by overriding &lt;code&gt;equals&lt;/code&gt; method. It is only possible to be sure about the result of the equality statement in these languages once the type implementation is reviewed.&lt;/p&gt;

&lt;p&gt;As we just saw, C# uses a memory reference approach for array assignment to reduce memory allocation. Go language, instead, uses deep copy for arrays.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Go
var array1 [3]int // Array of length 3
array1 = [3]int{ 1, 2, 3 } // Fill the array with numbers

var array2 [3]int // Array of length 3
array2 = array1 // Deep copy from array1 to array2

array1[0] = 9 // Change the first element in array1
array1; // { 9, 2, 3 }
array2; // { 1, 2, 3 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A tiny declaration change by removing array size in brackets (&lt;code&gt;var array1 []int&lt;/code&gt; and &lt;code&gt;var array2 []int&lt;/code&gt;) leads to &lt;code&gt;array slicing&lt;/code&gt; in Go. The result will be the opposite and the same as with C# reference array assignment.&lt;br&gt;
Go language forces programmers to pay attention to a number in square brackets.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffj66yb26lhejaf6swi6z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffj66yb26lhejaf6swi6z.png" alt="Grandma"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ruby authors consider all data structures as objects. Even primitive types, like integers, are objects, so everything is linked via a memory reference by default. The result for arrays will be similar to C# and Go slices. Some might expect the same behavior for Ruby integers, but instead, it will be a usual deep copy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Ruby
a = 1
b = a # Deep copy instead of referencing
a = 3
puts a # Holds 3
puts b # Holds the original value 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Passing an argument
&lt;/h2&gt;

&lt;p&gt;Language authors made three options to path an argument to a function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fryxieciy2lh0w5dy1o74.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fryxieciy2lh0w5dy1o74.png" alt="Big brain"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first one is a &lt;code&gt;pass by reference&lt;/code&gt; so that you can reassign a new value to the outer argument inside the function. &lt;br&gt;
The second is called &lt;code&gt;pass by value&lt;/code&gt;, and there are two options. One is to copy a reference to the memory address, you will not be able to reassign the value for an outer argument but will be able to modify the internals of the shared object. Another one is to make a deep copy of an argument so the changes inside the function will not affect the changes of a passed argument.&lt;/p&gt;

&lt;p&gt;Passing an argument does not fully correlate with the variable assignment &lt;code&gt;=&lt;/code&gt; behavior. Languages presented new symbols to differentiate the operation: &lt;code&gt;ref&lt;/code&gt; keyword. &lt;code&gt;&amp;amp;&lt;/code&gt; and &lt;code&gt;*&lt;/code&gt; signs. Many programmers find the latest two very confusing, for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if(*(struct foo**)deque_get(deq, i) != NULL &amp;amp;&amp;amp;
    (*(struct foo**)deque_get(deq, i))-&amp;gt;foo &amp;gt;= 1) {
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even for experienced engineers, it isn't easy to read.&lt;/p&gt;

&lt;p&gt;One may argue that large statements with many terms are relevant only to old languages, like C. Consider the number of terms for a property declaration in modern C#:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ReadOnly(true)]
internal required override string Prop { get; init; }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Method calls
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb25rhzve0j8f64tk5oez.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb25rhzve0j8f64tk5oez.png" alt="Wrong parameter orders meme"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Modern frameworks widely use function arguments. Here is a common approach to start a Web server in Go:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http.ListenAndServe(":3000", nil)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By reading this code you may guess that the first argument is a port number, but what about the second? Only after inspecting the function you can find out that it is a special controller, and if you pass &lt;code&gt;nil&lt;/code&gt; a default one will be used.&lt;/p&gt;

&lt;p&gt;A common JavaScript example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let obj = {a: { b: { c: 1 }}}
JSON.stringify(obj, null, 2)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Can a programmer know what &lt;code&gt;null&lt;/code&gt; represents there and &lt;code&gt;2&lt;/code&gt; without looking at the specification? (Answer: null is passed as an empty replacer, 2 is indentation size)&lt;/p&gt;

&lt;p&gt;You might create a function similar to the next one, which also raises questions about the arguments:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func("John", true, null, 1)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some IDEs, like JetBrains family, immediately show the names of the arguments, but programmers like to use other IDEs as well.&lt;br&gt;
Certain languages allow to rewrite the code with named arguments and even rearrange them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func(id: 1, name:"John", approved: true, email: null)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That approach is optional and many developers do not use it. The better solution for readability would be to oblige structural usage in all function calls, for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func({
  id: 1,
  name: "John", 
  approved: true,
  email: null
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  File search and jumps
&lt;/h2&gt;

&lt;p&gt;Modern software development and modern frameworks compel to create complex project structures.&lt;/p&gt;

&lt;p&gt;Try to count how many times you need to jump between files to understand the logic implementation. Are those files far away from each other and in different packages? Do you need to jump to a file to figure out some data structure, or can it be read immediately? Is it possible to declare types in the same file at the top location to simplify the reading? &lt;/p&gt;

&lt;p&gt;If you do not write much code it is possible to view &lt;a href="https://www.twitch.tv/programming" rel="noopener noreferrer"&gt;live programming streams&lt;/a&gt; and check how many context switches happens during file jumps.&lt;/p&gt;

&lt;h2&gt;
  
  
  Complexity
&lt;/h2&gt;

&lt;p&gt;I can provide many more examples, like breaking the reading flow in Go with &lt;code&gt;=&lt;/code&gt; and &lt;code&gt;:=&lt;/code&gt; operators, hidden importance  of &lt;code&gt;=&lt;/code&gt; sign and &lt;code&gt;hashCode&lt;/code&gt; overrides in Java and C#, JavaScript &lt;code&gt;call&lt;/code&gt;, &lt;code&gt;apply&lt;/code&gt; and &lt;code&gt;bind&lt;/code&gt; function calls, etc. The idea stays the same - how many terms a person needs to find, hold in memory to get the result, and how much time it requires to revise a term.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Popular programming languages made or applied revolutionary changes at some time. C language authors drastically simplified code writing and application support in comparison to programming in assembler. The default compilation result in C is still called &lt;code&gt;a.out&lt;/code&gt; or &lt;code&gt;assembly output&lt;/code&gt;. Java simplified working with memory via garbage collection. C# simplified Java statements and introduced Language Integrated Query. Go appeared as a simple alternative to C++ for network and console applications. Rust raised the bar of application stability and security. JavaScript, Python, and Ruby have low learning barriers. &lt;br&gt;
Language authors are restricted by previous versions and styles. Nevertheless, it will be great to see new language versions or new programming languages, reducing reading complexity as a major factor.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
