<?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:media="http://search.yahoo.com/mrss/"><channel><title><![CDATA[A Software Engineer's Blog]]></title><description><![CDATA[Thoughts, stories and ideas.]]></description><link>https://hugomarquez.mx/</link><image><url>https://hugomarquez.mx/favicon.png</url><title>A Software Engineer&apos;s Blog</title><link>https://hugomarquez.mx/</link></image><generator>Ghost 4.38</generator><lastBuildDate>Sat, 14 Mar 2026 13:02:07 GMT</lastBuildDate><atom:link href="https://hugomarquez.mx/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[Flutter vs Javascript]]></title><description><![CDATA[A brief comparison between flutter and javascript frameworks such as react]]></description><link>https://hugomarquez.mx/flutter-vs-javascript/</link><guid isPermaLink="false">645323880e0bab33d837eb9e</guid><category><![CDATA[Flutter]]></category><category><![CDATA[Flutter Series]]></category><category><![CDATA[Javascript]]></category><dc:creator><![CDATA[Hugo Márquez]]></dc:creator><pubDate>Thu, 04 May 2023 03:21:58 GMT</pubDate><media:content url="https://images.unsplash.com/photo-1521800641212-77d98bb90d21?crop=entropy&amp;cs=tinysrgb&amp;fit=max&amp;fm=jpg&amp;ixid=MnwxMTc3M3wwfDF8c2VhcmNofDF8fGJveGluZyUyMGdsb3ZlfGVufDB8fHx8MTY4MzE3MDI0OQ&amp;ixlib=rb-4.0.3&amp;q=80&amp;w=2000" medium="image"/><content:encoded><![CDATA[<img src="https://images.unsplash.com/photo-1521800641212-77d98bb90d21?crop=entropy&amp;cs=tinysrgb&amp;fit=max&amp;fm=jpg&amp;ixid=MnwxMTc3M3wwfDF8c2VhcmNofDF8fGJveGluZyUyMGdsb3ZlfGVufDB8fHx8MTY4MzE3MDI0OQ&amp;ixlib=rb-4.0.3&amp;q=80&amp;w=2000" alt="Flutter vs Javascript"><p>Comparing Flutter and JavaScript frameworks is like comparing apples and oranges. Flutter is a mobile app development framework, while JavaScript frameworks can be used for many different purposes. However, there are some reasons why Flutter may be a better choice than JavaScript frameworks for building mobile applications.</p><h3 id="performance">Performance</h3><p>Flutter uses a different approach to rendering user interfaces than JavaScript frameworks like React Native. Instead of using a bridge to communicate between JavaScript and the native platform, Flutter uses a fast and efficient rendering engine called Skia. This means that Flutter apps can have better performance and smoother animations than JavaScript-based apps.</p><h3 id="hot-reload">Hot Reload</h3><p>Flutter has a unique feature called Hot Reload, which allows developers to see changes they make to the code in real-time without having to restart the app. This can save developers a lot of time and make the development process more efficient. JavaScript-based frameworks like React Native also have a similar feature, but it&apos;s not as fast or reliable as Flutter&apos;s Hot Reload.</p><h3 id="widgets">Widgets</h3><p>Flutter uses a widget-based approach to building user interfaces, which makes it easier to create complex UI layouts and customize the look and feel of an app. In contrast, JavaScript-based frameworks like React Native use a component-based approach, which can be more cumbersome for complex layouts.</p><h3 id="tooling">Tooling</h3><p>Flutter has excellent tooling support, including Android Studio, Visual Studio Code, and IntelliJ IDEA. These IDEs have built-in support for Flutter, making it easy to develop, debug, and test Flutter apps. JavaScript-based frameworks also have good tooling support, but the ecosystem is more fragmented, and some tools may not work well together.</p><h3 id="community-support">Community Support</h3><p>Flutter is a relatively new framework, but it already has a growing community of developers and contributors. This means that there are plenty of resources available for learning Flutter, including online courses, tutorials, and forums. JavaScript-based frameworks also have a large community, but the sheer number of libraries and frameworks can be overwhelming for beginners.</p><h2 id="conclusion">Conclusion</h2><p>Both Flutter and JavaScript have their strengths and weaknesses, and the choice of which to use ultimately depends on the specific needs of the project. However, if you&apos;re looking to build a high-performance mobile app with a fast development cycle and excellent tooling support, Flutter may be the better choice.</p>]]></content:encoded></item><item><title><![CDATA[Dart Fundamentals I]]></title><description><![CDATA[A Dart programming language series to get up and running with dart and Flutter.

Dart Fundamentals I.]]></description><link>https://hugomarquez.mx/dart-fundamentals-i/</link><guid isPermaLink="false">640ea93d0e0bab33d837e769</guid><category><![CDATA[Dart]]></category><category><![CDATA[Dart Series]]></category><category><![CDATA[Flutter]]></category><category><![CDATA[Flutter Series]]></category><dc:creator><![CDATA[Hugo Márquez]]></dc:creator><pubDate>Tue, 02 May 2023 05:23:36 GMT</pubDate><media:content url="https://images.unsplash.com/photo-1596008194705-2091cd6764d4?crop=entropy&amp;cs=tinysrgb&amp;fit=max&amp;fm=jpg&amp;ixid=MnwxMTc3M3wwfDF8c2VhcmNofDJ8fGRhcnR8ZW58MHx8fHwxNjc4NjgyNDY2&amp;ixlib=rb-4.0.3&amp;q=80&amp;w=2000" medium="image"/><content:encoded><![CDATA[<img src="https://images.unsplash.com/photo-1596008194705-2091cd6764d4?crop=entropy&amp;cs=tinysrgb&amp;fit=max&amp;fm=jpg&amp;ixid=MnwxMTc3M3wwfDF8c2VhcmNofDJ8fGRhcnR8ZW58MHx8fHwxNjc4NjgyNDY2&amp;ixlib=rb-4.0.3&amp;q=80&amp;w=2000" alt="Dart Fundamentals I"><p>While we are studying Dart, it&apos;s important to keep the following facts in mind:</p><ul><li><strong>Everything </strong>in Dart is an <strong>object </strong>and every object is an <strong>instance of a class</strong>. Yes that&apos;s right, that includes: integers, functions and null. All objects, with the exception of null derived from the <strong>Object class</strong>.</li><li>Dart is strongly typed, yet type annotations are note required due to type inference.</li><li>If null safety is activated, variables can&apos;t be null, unless explicitly specified that they may be. Appending a <strong>question mark (?)</strong> to the end of a variable&apos;s type you make it <strong>nullable</strong>. The opposite can be said if we add an <strong>exclamation mark (!)</strong>, if a variable is null and it shouldn&apos;t be, it will throw an exception.</li><li>Dart supports generic types, such as ListObject&gt; (a list of any type of objects).</li><li>Dart allows top level functions such as main() and functions that are attached to a class or object such as instance and static methods. Functions within functions can create nested or local functions.</li><li>Dart lacks the public, private and protected keywords, but uses <strong>underscore (_)</strong> for reserved identifiers.</li></ul><h2 id="variables">Variables</h2><p>Variables keep track of references in a Dart program. A variable has a name or identifier and a value that it keeps track of. The variable type can be inferred by the variable&apos;s value, but it can be explicitly specified. </p><pre><code class="language-dart">// Some variable examples
var greet = &quot;Hello Hugo!&quot;;

// Specifying its type
String my_variable = &quot;This is my variable&quot;;

// A variable can be dynamic, but we can specify the Object class to
// accept any value
Object name = &quot;Hugo Marquez&quot;;</code></pre><h3 id="variable-declaration">Variable Declaration</h3><p>We can use the var keyword to declare a variable and with dart&apos;s type inference, it will automatically determine the variable data type based on its value. The syntax is as follow:</p><pre><code class="language-dart">// Variable declaration
&lt;type&gt; &lt;the variable name&gt; = &lt;values&gt;;
var myVar = &quot;A simple string&quot;;
String myString = &quot;A simple string&quot;;

// Multipe variable declaration
&lt;type&gt; &lt;var1, var2, var3&gt;;
String str1, str2, str3;
int a,b,c;</code></pre><h3 id="const-and-final">Const and Final</h3><p>We use final and const when we want to declare our variables as constants or we do not want to modify its value in the future. The const keyword is used to define compile-time constants.</p><pre><code class="language-dart">// Final variables
final firstName = &apos;Hugo&apos;;
final String lastName = &quot;Marquez&quot;;

// Const variables
const a = 10;

// Constant value
const uniqueValue = const [];</code></pre><h3 id="default-values">Default Values</h3><p>When creating an <strong>uninitialized variable</strong> of the nullable type, they are created with the <strong>null value</strong>. Local variables do not need to be initialized when it is declared, but it must have a value before it is used. Top-level and class variables are lazily initialized, thus the initialization code is executed the first time the variable is needed.</p><pre><code class="language-dart">// Nullable variable (numeric)
int? counter;
assert(counter == null); // this should assert to true

// If null safety is enabled, we first need to initialize
// the null value of a variable
int counter = 0;</code></pre><h3 id="darts-semicolon">Dart&apos;s Semicolon</h3><p>In Dart, the semicolon is used to finalize or conclude a sentence, this to indicate that a statement has concluded. If it is not used correctly the compiler will <strong>throw an exception</strong>.</p><h2 id="darts-keywords">Dart&apos;s Keywords</h2><p>There are 61 reserved keywords in the dart programming language, this keywords are reserved for the compiler and can&apos;t be used as a variable&apos;s identifier, class or function name. <strong>Keywords are case sensitive</strong>, so they must be written exactly as defined. This are some of the most common keywords in the dart programming language:</p><!--kg-card-begin: markdown--><table>
<thead>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>abstract</td>
<td>Else</td>
<td>import</td>
<td>super</td>
</tr>
<tr>
<td>as</td>
<td>Enum</td>
<td>In</td>
<td>switch</td>
</tr>
<tr>
<td>Assert</td>
<td>export</td>
<td>interface</td>
<td>sync</td>
</tr>
<tr>
<td>async</td>
<td>extends</td>
<td>Is</td>
<td>This</td>
</tr>
<tr>
<td>await</td>
<td>extension</td>
<td>Library</td>
<td>throw</td>
</tr>
<tr>
<td>Break</td>
<td>external</td>
<td>mixin</td>
<td>True</td>
</tr>
<tr>
<td>Case</td>
<td>factory</td>
<td>New</td>
<td>Try</td>
</tr>
<tr>
<td>Catch</td>
<td>False</td>
<td>Null</td>
<td>typedef</td>
</tr>
<tr>
<td>Class</td>
<td>Final</td>
<td>on1</td>
<td>Var</td>
</tr>
<tr>
<td>Const</td>
<td>finally</td>
<td>operator</td>
<td>void</td>
</tr>
<tr>
<td>Continue</td>
<td>For</td>
<td>part</td>
<td>while</td>
</tr>
<tr>
<td>covarient</td>
<td>Function</td>
<td>Rethrow</td>
<td>with</td>
</tr>
<tr>
<td>Default</td>
<td>get</td>
<td>Return</td>
<td>yield</td>
</tr>
<tr>
<td>deffered</td>
<td>hide</td>
<td>set</td>
<td></td>
</tr>
<tr>
<td>Do</td>
<td>If</td>
<td>show</td>
<td></td>
</tr>
<tr>
<td>dynamic</td>
<td>implements</td>
<td>static</td>
<td></td>
</tr>
</tbody>
</table>
<!--kg-card-end: markdown--><h2 id="data-types">Data Types</h2><h3 id="numbers">Numbers</h3><p>Numbers are used to keep track of numeric values, in Dart there are two types of numeric data types:</p><ul><li><strong>Integers</strong>: where the value is a whole number or a non-fractional value. It provides a 64-bit non-decimal values that ranges from -263 to 263.</li><li><strong>Doubles</strong>: a double represents 64-bit information with double precision for floating numbers. </li></ul><pre><code class="language-dart">// Integer examples
int a = 10;
int b = 35;

// Double examples
double c = 3.4;
double pi - 3.1416;</code></pre><h4 id="number-properties">Number Properties</h4><!--kg-card-begin: markdown--><table>
<thead>
<tr>
<th>Properties</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>Hashcode</td>
<td>Returns the hash code of the given number.</td>
</tr>
<tr>
<td>isFinite</td>
<td>Returns true if the provided number is finite.</td>
</tr>
<tr>
<td>isInfinite</td>
<td>Returns true if the number is infinite.</td>
</tr>
<tr>
<td>isNan</td>
<td>Returns true if the number is not negative.</td>
</tr>
<tr>
<td>isNegative</td>
<td>Returns true if the number is negative.</td>
</tr>
<tr>
<td>Sign</td>
<td>Returns -1, 0 or 1 depending on the provided number sign.</td>
</tr>
<tr>
<td>isEven</td>
<td>Returns true if the provided number is an even number.</td>
</tr>
<tr>
<td>isOdd</td>
<td>Returns true if the given number is odd.</td>
</tr>
</tbody>
</table>
<!--kg-card-end: markdown--><h4 id="number-methods">Number Methods</h4><!--kg-card-begin: markdown--><table>
<thead>
<tr>
<th>Method</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>abs()</td>
<td>Returns the absolute value of a given number.</td>
</tr>
<tr>
<td>ceil()</td>
<td>Returns the ceiling value of a given number.</td>
</tr>
<tr>
<td>floor()</td>
<td>Returns the floor value of a given number.</td>
</tr>
<tr>
<td>compareTo()</td>
<td>It compares the value with other number.</td>
</tr>
<tr>
<td>remainder()</td>
<td>Returns the truncated remainder after dividing the two numbers.</td>
</tr>
<tr>
<td>round()</td>
<td>Returns a round of the number.</td>
</tr>
<tr>
<td>toDouble()</td>
<td>Returns the double equivalent representation of a number.</td>
</tr>
<tr>
<td>toInt()</td>
<td>Returns the integer equivalent representation of a number.</td>
</tr>
<tr>
<td>toString()</td>
<td>Returns the String equivalent representation of the number.</td>
</tr>
<tr>
<td>truncate()</td>
<td>Returns integer after discarding the fraction digits.</td>
</tr>
<tr>
<td>parse()</td>
<td>Converts a numeric string to a number.</td>
</tr>
</tbody>
</table>
<!--kg-card-end: markdown--><h3 id="strings">Strings</h3><p>A string is a sequence of characters that are stored on an array. In Dart strings can be declared with either a single or double quotation marks. A Dart string is made up of UTF-16 code units. Strings are immutable, which means they cannot be changeable after they are created.</p><pre><code class="language-dart">// String examples
void main() {
  var hello = &apos;Hello World!&apos;;
  var message = &quot;This string was declared with double 
  	quotation marks :)&quot;;
   
   var x = 100;
   var y = 30;
   
   // String interpolation, concatenation and printing
   String initial_str = &quot;The sum of &quot;;
   String x_str = &quot;x: ${x} and &quot;;
   String y_str = &quot;y: ${y}&quot;;
   String result = &quot;is ${x+y}&quot;;
   
   print(initial_str + x_str + y_str + result);
}
</code></pre><h4 id="string-properties">String Properties</h4><!--kg-card-begin: markdown--><table>
<thead>
<tr>
<th>Property</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>codeUnits</td>
<td>Returns an unmodified list of UTF-16 code units of the provided string</td>
</tr>
<tr>
<td>isEmpty</td>
<td>If the string is empty, it returns true.</td>
</tr>
<tr>
<td>Length</td>
<td>Returns the length of the string, including whitespaces.</td>
</tr>
</tbody>
</table>
<!--kg-card-end: markdown--><h4 id="string-methods">String Methods</h4><!--kg-card-begin: markdown--><table>
<thead>
<tr>
<th>Method</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>toLowerCase()</td>
<td>It lowercases all characters in the specified string.</td>
</tr>
<tr>
<td>toUpperCase()</td>
<td>It uppercases all characters in the provided string.</td>
</tr>
<tr>
<td>trim()</td>
<td>It removes all whitespaces from the string.</td>
</tr>
<tr>
<td>compareTo()</td>
<td>It compares one string with another.</td>
</tr>
<tr>
<td>replaceAll()</td>
<td>Replaces all substrings that match the specified pattern with the string.</td>
</tr>
<tr>
<td>split()</td>
<td>Devides the string at the supplied delimiter and returns a list of substrings.</td>
</tr>
<tr>
<td>substring()</td>
<td>Returns the substring from start to end inclusive.</td>
</tr>
<tr>
<td>toString()</td>
<td>Returns a string representation of a given object.</td>
</tr>
<tr>
<td>codeUnitAt()</td>
<td>Returns the 16-bits code unit at the given index.</td>
</tr>
</tbody>
</table>
<!--kg-card-end: markdown--><h3 id="booleans">Booleans</h3><p>The Booleans in Dart represents a true or false and the Boolean keyword is <strong>bool</strong>. The numeric values of 0 and 1 can&apos;t be used to represent true or false.</p><pre><code class="language-dart">// Booleans
bool valid_response = true;
bool invalid_response = false;</code></pre><h3 id="lists">Lists</h3><p>In the dart programming language a list is a collection of ordered things and it is comparable to an array. The list&apos;s items are separated by a comma inside square brackets []. Lists are divided into two categories:</p><ul><li><strong>Fixed length lists:</strong> The length of the list is provided and it is not possible to change its size at runtime.</li><li><strong>Growable lists:</strong> It is declared without specifying a size. At runtime it is possible to change it&apos;s size</li></ul><pre><code class="language-dart">void main() {
  // List is like an array
  var list = [1, 2, 3];
  
  // Fixed length list
  var fixed_list = new List(3);
  fixed_list[0] = 1;
  fixed_list[1] = 2;
  fixed_list[2] = 3;
  print(fixed_list);
  
  // Growable List
  var grow_list = new List();
  grow_list.add(1);
  grow_list.add(2);
  grow_list.add(3);
  print(grow_list);
  
  // The addAll()
  grow_list.addAll([1, 2, 3]);
  
  // The insert(index, value);
  grow_list.insert(2, 4);
  
  // The insertAll(index, iterable_list_of_values)
  grow_list.insertAll(3, [4, 5, 6, 7]);
  
  // The replaceRange(int start, int end, iterable)
  grow_list.replaceRange(1, 3, [5, 6, 7, 8]);
  
  // The remove(value)
  grow_list.remove(1);
  
  // The removeAt(index):
  grow_list.removeAt(2);
  
  // The removeLast()
  grow_list.removeLast();
  
  // The removeRange(int start, int end)
  grow_list.removeRange(0, 3);
  
  // List iteration
  grow_list.forEach((elements) {
    print(&quot;${grow_list.indexOf(elements)}: $elements&quot;));
  });
}</code></pre><h4 id="list-properties">List Properties</h4><!--kg-card-begin: markdown--><table>
<thead>
<tr>
<th>Property</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>First</td>
<td>Returns the first element of the list.</td>
</tr>
<tr>
<td>isEmpty</td>
<td>Returns true if the list is empty.</td>
</tr>
<tr>
<td>isNotEmpty</td>
<td>Returns true if the list has at least one element</td>
</tr>
<tr>
<td>Length</td>
<td>Returns the list&apos;s length</td>
</tr>
<tr>
<td>Last</td>
<td>Returns the list&apos;s last element.</td>
</tr>
<tr>
<td>Reversed</td>
<td>Returns a list in reverse order.</td>
</tr>
<tr>
<td>Single</td>
<td>Whether the list has one element and returns it.</td>
</tr>
</tbody>
</table>
<!--kg-card-end: markdown--><h4 id="list-methods">List Methods</h4><!--kg-card-begin: markdown--><table>
<thead>
<tr>
<th>Methods</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>add()</td>
<td>Object is insterted at the end of the list.</td>
</tr>
<tr>
<td>addAll()</td>
<td>Inserts several values into a list.</td>
</tr>
<tr>
<td>insert()</td>
<td>Inserts an element at the provided index.</td>
</tr>
<tr>
<td>insertAll()</td>
<td>Inserts multiple elements at the provided index.</td>
</tr>
<tr>
<td>replaceRange()</td>
<td>Update list items within a defined range.</td>
</tr>
<tr>
<td>remove()</td>
<td>Removes one element from the list at a time, it can recognize elements as arguments.</td>
</tr>
<tr>
<td>removeAt()</td>
<td>Returns an element removed from the list at the provided index.</td>
</tr>
<tr>
<td>removeLast()</td>
<td>Removes the last element of the list.</td>
</tr>
</tbody>
</table>
<!--kg-card-end: markdown--><h3 id="sets">Sets</h3><p>Sets in Dart are an unordered collection of elements of the same type. It&apos;s similar to an array, except it is not ordered. Sets do not allow us to insert duplicate values, thus the values on a set must be unique.</p><pre><code class="language-dart">// Sets declaration
// var setName = &lt;type&gt;{};
// Set&lt;type&gt; setName = {};

var firstNames = &lt;String&gt;{&apos;Hugo&apos;, &apos;John&apos;, &apos;Alex&apos;};

// Accessing a set value at index 2
print(firstNames.elementAt(2));

// Finding a set by value
firstNames.contains(&apos;Hugo&apos;);

// Remove all elements of a set
firstNames.clear();

// Cast set to a list
// List&lt;type&gt; list_name = set_name.toList();
List&lt;String&gt; listFirstNames = firstNames.toList();
</code></pre><h4 id="set-operations">Set operations</h4><p>Sets in the Dart programming language has the following operations:</p><ul><li>Union: It merges the values of two provided sets.</li><li>Intersection: Returns the intersection between sets, all elements shared by both.</li><li>Subtraction: subtracts the elements (setA - setB), members of setB that are not present in setA are subtracted.</li></ul><h3 id="maps">Maps</h3><p>Map types are used to represent a key-value pair, where each key has a value associated with it. Any type of value and key can be used, but a key in a map must be unique. Curly braces are used to defined a map and a comma separates each pair.</p><pre><code class="language-dart">// Map literal declaration
var employees = {&apos;name&apos;: &apos;Hugo&apos;, &apos;last_name&apos;: &apos;Marquez&apos;, &apos;branch&apos;: &apos;Software Engineer&apos;};

// Map constructor declaration
var employees = new Map();
employees[&apos;name&apos;] = &apos;Hugo&apos;;
employees[&apos;last_name&apos;] = &apos;Marquez&apos;;
employees[&apos;branch&apos;] = &apos;Software Engineer&apos;;

// The Map.addAll(Map&lt;key, value&gt; other);
Map teachers = {&apos;name&apos;: &apos;John&apos;, age: &apos;30&apos;};
teachers.addAll({&apos;dept&apos;: &apos;Math&apos;, email:&apos;john@school.org&apos;});

// The Map.remove(object-key);
teachers.remove(&apos;age&apos;);

// Iterating over a map
// Map.forEach(void f(K key V value));
teachers.forEach((k, v) =&gt; print(&apos;${k} : ${v}&apos;));

// Clearing a map
teachers.clear();

</code></pre><h4 id="map-properties">Map Properties</h4><!--kg-card-begin: markdown--><table>
<thead>
<tr>
<th>Property</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>Keys</td>
<td>Returns all the keys as an iterable object.</td>
</tr>
<tr>
<td>Values</td>
<td>Returns all values as an interable object.</td>
</tr>
<tr>
<td>Length</td>
<td>Returns the length of the map object.</td>
</tr>
<tr>
<td>isEmpty</td>
<td>If the map object contains no values, returns true.</td>
</tr>
<tr>
<td>isNotEmpty</td>
<td>If the map object contains at least one value, returns true</td>
</tr>
</tbody>
</table>
<!--kg-card-end: markdown--><h3 id="enums-in-dart">Enums in Dart</h3><p>Enumerators are a collection of known values as elements, members, etc. It&apos;s defined using the <strong>enum</strong> keyword and a comma separated list of valid identifiers. It is enclosed by curly braces and the syntax is as follows:</p><pre><code class="language-dart">// Enums in dart
// enum &lt;enum_name&gt; {
//   const1,
//   const2,
//   const..n,
// }

enum months {
  Jan,
  Feb,
  March,
  April,
  May,
  June,
  July,
  Aug,
  Sept,
  Oct,
  Nov,
  Dec,
}</code></pre><h3 id="runes">Runes</h3><p>As defined previously, a string is a collection and sequence of characters of UTF-16 code units. Well a Rune is a unique string of Unicode UTF-32 code units, that enables us to express unique syntax. For example, the special character for a &#x2764;&#xFE0F; is identical to the Unicode u2665, where u stands for Unicode and the digits are hexadecimal integers. </p><pre><code class="language-dart">// Dart runes are UTF-32 code units
void main() {
  var heart_symb = &apos;\u2665&apos;;
  print( heart_symb );
}</code></pre><h3 id="symbols">Symbols</h3><p>A symbol in the dart programming language are used to specify an identifier or operator. In Dart the Hash (#) symbol is followed by the name of the identifier to define a Symbol. Symbols are used in dart as a <a href="https://en.wikipedia.org/wiki/Reflective_programming">reflection technique</a> in combination with the mirror library.</p><pre><code class="language-dart">import &apos;dart:core&apos;;
import &apos;dart:mirror&apos;;

void main() {
  Symbol library = new Symbol(&apos;my_lib&apos;);
  String name_of_libs = MirrorSystem.getName(library);
}</code></pre><h2 id="whats-next">What&apos;s next?</h2><p>For Part II we will use the above knowledge and continue our journey on the dart programming language with control flow statements, constants, switch-cases, conditional statements and dart functions.</p><p>Cheers! &#x1F37B;</p><hr><h2 id="resources">Resources</h2><p>Great news! The dart and flutter ecosystem is very well documented and full of examples and tutorials all over the internet. Here is a list, to mention a few, of useful resources:</p><figure class="kg-card kg-bookmark-card"><a class="kg-bookmark-container" href="https://dart.dev/"><div class="kg-bookmark-content"><div class="kg-bookmark-title">Dart programming language</div><div class="kg-bookmark-description">Dart is a client-optimized language for fast apps on any platform</div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="https://dart.dev/assets/img/touch-icon-iphone-retina.png" alt="Dart Fundamentals I"><span class="kg-bookmark-author">Dart</span></div></div><div class="kg-bookmark-thumbnail"><img src="https://dart.dev/assets/shared/dart-logo-for-shares.png?2" alt="Dart Fundamentals I"></div></a></figure><figure class="kg-card kg-bookmark-card"><a class="kg-bookmark-container" href="https://www.goodreads.com/book/show/62685785-mastering-flutter?from_search=true&amp;from_srp=true&amp;qid=nUIZl0a3Qk&amp;rank=2"><div class="kg-bookmark-content"><div class="kg-bookmark-title">Mastering Flutter: A Beginner&#x2019;s Guide (Mastering Comput&#x2026;</div><div class="kg-bookmark-description">Discover and share books you love on Goodreads.</div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="https://www.goodreads.com/favicon.ico" alt="Dart Fundamentals I"><span class="kg-bookmark-author">Goodreads</span><span class="kg-bookmark-publisher">Sufyan bin Uzayr</span></div></div><div class="kg-bookmark-thumbnail"><img src="https://images-na.ssl-images-amazon.com/images/S/compressed.photo.goodreads.com/books/1663820527i/62685785.jpg" alt="Dart Fundamentals I"></div></a></figure><figure class="kg-card kg-bookmark-card"><a class="kg-bookmark-container" href="https://en.wikipedia.org/wiki/Reflective_programming"><div class="kg-bookmark-content"><div class="kg-bookmark-title">Reflective programming - Wikipedia</div><div class="kg-bookmark-description"></div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="https://en.wikipedia.org/static/apple-touch/wikipedia.png" alt="Dart Fundamentals I"><span class="kg-bookmark-author">Wikimedia Foundation, Inc.</span><span class="kg-bookmark-publisher">Contributors to Wikimedia projects</span></div></div><div class="kg-bookmark-thumbnail"><img src="https://upload.wikimedia.org/wikipedia/en/thumb/9/99/Question_book-new.svg/50px-Question_book-new.svg.png" alt="Dart Fundamentals I"></div></a></figure>]]></content:encoded></item><item><title><![CDATA[The Dart Programming Language]]></title><description><![CDATA[A Dart programming language introduction to get up and running with dart and Flutter.]]></description><link>https://hugomarquez.mx/the-dart-programming-languague/</link><guid isPermaLink="false">63f2a6d80e0bab33d837e4ed</guid><category><![CDATA[Dart]]></category><category><![CDATA[Flutter]]></category><category><![CDATA[Dart Series]]></category><category><![CDATA[Flutter Series]]></category><dc:creator><![CDATA[Hugo Márquez]]></dc:creator><pubDate>Mon, 01 May 2023 19:33:47 GMT</pubDate><media:content url="https://images.unsplash.com/photo-1577511425081-0ec68e1bd454?crop=entropy&amp;cs=tinysrgb&amp;fit=max&amp;fm=jpg&amp;ixid=MnwxMTc3M3wwfDF8c2VhcmNofDEwfHxkYXJ0fGVufDB8fHx8MTY3Njg3NjA2Ng&amp;ixlib=rb-4.0.3&amp;q=80&amp;w=2000" medium="image"/><content:encoded><![CDATA[<img src="https://images.unsplash.com/photo-1577511425081-0ec68e1bd454?crop=entropy&amp;cs=tinysrgb&amp;fit=max&amp;fm=jpg&amp;ixid=MnwxMTc3M3wwfDF8c2VhcmNofDEwfHxkYXJ0fGVufDB8fHx8MTY3Njg3NjA2Ng&amp;ixlib=rb-4.0.3&amp;q=80&amp;w=2000" alt="The Dart Programming Language"><p>Dart is a general purpose, open source, object-oriented, type-safe programming language with C-Style syntax created by google in 2011. It is used to create frontend UIs for online and mobile applications. It&apos;s influenced by other programming languages such as Java, C# and Javascript. Dart is a client-optimized programming language, where its main purpose is to be used on cross-platform application development using the flutter framework. &#xA0;</p><p>Ok, so in order to understand this definition, we need to break it down by its components. Some of it might me obvious, but for the fun of it, I&apos;ll add a basic summery of the definitions and links to Wikipedia articles to whomever might need it.</p><ul><li><a href="https://en.wikipedia.org/wiki/Object-oriented_programming">Object-Oriented</a>: &quot;It&apos;s a programming paradigm based on the concept of object&quot;. </li><li><a href="https://en.wikipedia.org/wiki/Type_safety#cite_note-saraswat-java-2">Type-Safe</a>: &quot;Type safety and type soundness are the extent to which a programming language discourages or prevents type errors<strong>&quot;.</strong> In other words, only the operations that can be performed on data in the language, are those allowed by type of data.</li></ul><p>Great! let us go deeper on type soundness, as Dart is and has a <strong>static type check</strong> and <strong>runtime check</strong>. The first one is used in compilation on the deployment/production phase while the latter is used for the development phase and fast prototyping. Dart also has a <strong>dynamic type</strong>, where type check ups are run at runtime. Dart also uses <strong>type inference</strong>, where the type of a variable is defined by its value on its creation.</p><h2 id="sound-null-safety">Sound null safety</h2><p>In Dart, values cannot be null unless it is specified to be null, data can be nullable or not, but not both. If a variable in dart is set to be non-nullable, that variable <strong>will always be non-nullable</strong>.</p><h2 id="the-compiler">The Compiler</h2><p>Dart uses a compiler to compile source code to machine code that can be run on an architecture or the dart virtual machine. We will focus on the Dart VM later on, but for now we will list the following architecture where dart can be run.</p><!--kg-card-begin: markdown--><table>
<thead>
<tr>
<th>Architecture</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>ARM 32</td>
<td>JIT or AOT</td>
</tr>
<tr>
<td>ARM 64</td>
<td>JIT or AOT</td>
</tr>
<tr>
<td>X86_64</td>
<td>JIT or AOT</td>
</tr>
<tr>
<td>Web (Javascript)</td>
<td>dartdevc or dart2js</td>
</tr>
</tbody>
</table>
<!--kg-card-end: markdown--><p>Where the following definitions are in order:</p><ul><li><a href="https://en.wikipedia.org/wiki/Just-in-time_compilation">JIT</a>: Stands for Just In Time compilation.</li><li><a href="https://en.wikipedia.org/wiki/Ahead-of-time_compilation">AOT</a>: Stands for Ahead Of Time compilation.</li><li><a href="https://dart.dev/tools/dart2js">dart2js</a>: Is the dart to javascript compiler.</li><li><a href="https://dart.dev/tools/dartdevc">dartdevc</a>: Is the dart development compiler.</li></ul><h3 id="dart-phases">Dart phases</h3><p>Ok, so you might be wondering, What&apos;s with all that different compilation stuff going on here? The answer is quite simple, Dart is trying to breach the gap between the developer experience and the customer experience by providing developers with tools such as just in time compilation and hot reloading while in production or deployment using ahead of time compilation.</p><p>Just think about it like this:</p><!--kg-card-begin: markdown--><table>
<thead>
<tr>
<th>Development Phase</th>
<th>Production phase</th>
</tr>
</thead>
<tbody>
<tr>
<td>JIT</td>
<td>AOT</td>
</tr>
<tr>
<td>Hot-Reloading</td>
<td>Better performance</td>
</tr>
<tr>
<td>Happy developer</td>
<td>Happy customer</td>
</tr>
</tbody>
</table>
<!--kg-card-end: markdown--><h3 id="dart-cli">Dart CLI</h3><p>The dart CLI is the command line interface tool used for creating, compiling, migrating, installing dependencies and more. There are some common available commands and they are as follow:</p><pre><code class="language-text">Manage your Flutter app development.

Common commands:

  flutter create &lt;output directory&gt;
    Create a new Flutter project in the specified directory.

  flutter run [options]
    Run your Flutter application on an attached device or in an emulator.

Usage: flutter &lt;command&gt; [arguments]

Global options:
-h, --help                  Print this usage information.
-v, --verbose               Noisy logging, including all shell commands
                            executed.
                            If used with &quot;--help&quot;, shows hidden options. If used
                            with &quot;flutter doctor&quot;, shows additional diagnostic
                            information. (Use &quot;-vv&quot; to force verbose logging in
                            those cases.)
-d, --device-id             Target device id or name (prefixes allowed).
    --version               Reports the version of this tool.
    --suppress-analytics    Suppress analytics reporting when this command runs.

Available commands:

Flutter SDK
  bash-completion   Output command line shell completion setup scripts.
  channel           List or switch Flutter channels.
  config            Configure Flutter settings.
  doctor            Show information about the installed tooling.
  downgrade         Downgrade Flutter to the last active version for the current
                    channel.
  precache          Populate the Flutter tool&apos;s cache of binary artifacts.
  upgrade           Upgrade your copy of Flutter.

Project
  analyze           Analyze the project&apos;s Dart code.
  assemble          Assemble and build Flutter resources.
  build             Build an executable app or install bundle.
  clean             Delete the build/ and .dart_tool/ directories.
  create            Create a new Flutter project.
  drive             Run integration tests for the project on an attached device
                    or emulator.
  gen-l10n          Generate localizations for the current project.
  pub               Commands for managing Flutter packages.
  run               Run your Flutter app on an attached device.
  test              Run Flutter unit tests for the current project.

Tools &amp; Devices
  attach            Attach to a running app.
  custom-devices    List, reset, add and delete custom devices.
  devices           List all connected devices.
  emulators         List, launch and create emulators.
  install           Install a Flutter app on an attached device.
  logs              Show log output for running Flutter apps.
  screenshot        Take a screenshot from a connected device.
  symbolize         Symbolize a stack trace from an AOT-compiled Flutter app.

Run &quot;flutter help &lt;command&gt;&quot; for more information about a command.
Run &quot;flutter help -v&quot; for verbose help output, including less commonly used
options.
</code></pre><h3 id="dart-vm">Dart VM</h3><p>The Dart VM is not a virtual machine like the Java Virtual Machine, in a way, it is all the components that provides an execution environment for a high-level programming language. So too much can be said for the VM but to keep things simple, we can say that the Dart VM includes the following:</p><!--kg-card-begin: markdown--><ul>
<li>The runtime system.</li>
<li>The development components such as:
<ul>
<li>debugging tools.</li>
<li>hot-reloading.</li>
<li>etc.</li>
</ul>
</li>
<li>JIT compilation pipeline.</li>
<li>AOT compilation pipeline.</li>
</ul>
<!--kg-card-end: markdown--><p>The heap memory uses a garbage collector to reclaim memory allocated but no longer used. The Dart VM can execute the code in 2 ways from source through JIT or AOT and from snapshots which includes JIT, AOT or kernel snapshots.</p><hr><p>Thank you for reading my post, this should be enough information for us to start our journey with the Dart and Flutter ecosystem. I hope you find this information useful and sparks the fire to get you started with Dart and flutter. The next series of post will be more in depth and with a more hands-on approach.</p><p>Cheers! &#x1F37B;</p><h2 id="resources">Resources</h2><figure class="kg-card kg-bookmark-card"><a class="kg-bookmark-container" href="https://dart.dev/overview"><div class="kg-bookmark-content"><div class="kg-bookmark-title">Dart overview</div><div class="kg-bookmark-description">A short introduction to Dart</div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="https://dart.dev/assets/img/touch-icon-iphone-retina.png" alt="The Dart Programming Language"><span class="kg-bookmark-author">Dart</span></div></div><div class="kg-bookmark-thumbnail"><img src="https://dart.dev/assets/shared/dart-logo-for-shares.png?2" alt="The Dart Programming Language"></div></a></figure><figure class="kg-card kg-bookmark-card"><a class="kg-bookmark-container" href="https://dart.dev/"><div class="kg-bookmark-content"><div class="kg-bookmark-title">Dart programming language</div><div class="kg-bookmark-description">Dart is a client-optimized language for fast apps on any platform</div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="https://dart.dev/assets/img/touch-icon-iphone-retina.png" alt="The Dart Programming Language"><span class="kg-bookmark-author">Dart</span></div></div><div class="kg-bookmark-thumbnail"><img src="https://dart.dev/assets/shared/dart-logo-for-shares.png?2" alt="The Dart Programming Language"></div></a></figure><figure class="kg-card kg-bookmark-card"><a class="kg-bookmark-container" href="https://dartpad.dev/?"><div class="kg-bookmark-content"><div class="kg-bookmark-title">DartPad</div><div class="kg-bookmark-description">An online Dart editor with support for console, web, and Flutter apps.</div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="https://dartpad.dev/dart-192.png" alt="The Dart Programming Language"></div></div><div class="kg-bookmark-thumbnail"><img src="https://dartpad.dev/dart-192.png" alt="The Dart Programming Language"></div></a></figure>]]></content:encoded></item><item><title><![CDATA[Rails Query Optimization]]></title><description><![CDATA[<p>Ruby on Rails is a pretty straightforward framework to get started on, it is easy to understand and learn, but to achieve mastery it requires time, just like any other framework or tool. &quot;Rails do not scale&quot;, this is one of the biggest misconception and argument used to</p>]]></description><link>https://hugomarquez.mx/rails-query-optimization/</link><guid isPermaLink="false">631606dc0e0bab33d837e328</guid><category><![CDATA[Ruby]]></category><category><![CDATA[Ruby on Rails]]></category><category><![CDATA[SQL]]></category><dc:creator><![CDATA[Hugo Márquez]]></dc:creator><pubDate>Mon, 05 Sep 2022 22:38:43 GMT</pubDate><media:content url="https://images.unsplash.com/photo-1575620442792-9a2688f60570?crop=entropy&amp;cs=tinysrgb&amp;fit=max&amp;fm=jpg&amp;ixid=MnwxMTc3M3wwfDF8c2VhcmNofDl8fHJhaWxzfGVufDB8fHx8MTY2MjM5MjMwMg&amp;ixlib=rb-1.2.1&amp;q=80&amp;w=2000" medium="image"/><content:encoded><![CDATA[<img src="https://images.unsplash.com/photo-1575620442792-9a2688f60570?crop=entropy&amp;cs=tinysrgb&amp;fit=max&amp;fm=jpg&amp;ixid=MnwxMTc3M3wwfDF8c2VhcmNofDl8fHJhaWxzfGVufDB8fHx8MTY2MjM5MjMwMg&amp;ixlib=rb-1.2.1&amp;q=80&amp;w=2000" alt="Rails Query Optimization"><p>Ruby on Rails is a pretty straightforward framework to get started on, it is easy to understand and learn, but to achieve mastery it requires time, just like any other framework or tool. &quot;Rails do not scale&quot;, this is one of the biggest misconception and argument used to downplay the framework. In my opinion bad system design no matter the language or framework will always be slow and hard to scale.</p><h2 id="n1">N+1</h2><p>The N+1 problem is one of the most common anti-patterns that affects performance in a very meaningful way. This happens when a query is executed as a result of the previous query. This issue might not be as obvious when you have a small application or dataset, but if we want to keep our application light and fast we need to remove this anti-pattern.</p><p>Here is an example:</p><figure class="kg-card kg-code-card"><pre><code class="language-ruby">class User &lt; ApplicationRecord
  has_many :tweets
end</code></pre><figcaption>The User Class</figcaption></figure><figure class="kg-card kg-code-card"><pre><code class="language-ruby">class Tweet &lt; ApplicationRecord
  belongs_to :user
end
</code></pre><figcaption>The Tweet Class</figcaption></figure><pre><code class="language-ruby">Tweet.all.each do |tweet|
  puts &quot;#{tweet.title} was written by #{tweet.user.username}&quot;
end
</code></pre><p>This will produce the following queries:</p><pre><code class="language-bash">Tweet Load (0.4ms)  SELECT &quot;tweets&quot;.* FROM &quot;tweets&quot;
  User Load (0.2ms)  SELECT &quot;users&quot;.* FROM &quot;users&quot; WHERE &quot;users&quot;.&quot;id&quot; = ? LIMIT ?  [[&quot;id&quot;, 1], [&quot;LIMIT&quot;, 1]]
  User Load (0.2ms)  SELECT &quot;users&quot;.* FROM &quot;users&quot; WHERE &quot;users&quot;.&quot;id&quot; = ? LIMIT ?  [[&quot;id&quot;, 1], [&quot;LIMIT&quot;, 1]]
  User Load (0.3ms)  SELECT &quot;users&quot;.* FROM &quot;users&quot; WHERE &quot;users&quot;.&quot;id&quot; = ? LIMIT ?  [[&quot;id&quot;, 2], [&quot;LIMIT&quot;, 1]]
  User Load (0.2ms)  SELECT &quot;users&quot;.* FROM &quot;users&quot; WHERE &quot;users&quot;.&quot;id&quot; = ? LIMIT ?  [[&quot;id&quot;, 2], [&quot;LIMIT&quot;, 1]]
  User Load (0.2ms)  SELECT &quot;users&quot;.* FROM &quot;users&quot; WHERE &quot;users&quot;.&quot;id&quot; = ? LIMIT ?  [[&quot;id&quot;, 2], [&quot;LIMIT&quot;, 1]]
  User Load (0.2ms)  SELECT &quot;users&quot;.* FROM &quot;users&quot; WHERE &quot;users&quot;.&quot;id&quot; = ? LIMIT ?  [[&quot;id&quot;, 2], [&quot;LIMIT&quot;, 1]]
  </code></pre><p>In this example, we first retrieve all the <strong>Tweet</strong> objects and then for every tweet we retrieve the users. There are 6 tweets in the database, this example executes 7 queries.</p><p>Imagine if we have a bigger application, &#xA0;where there are 15,000 tweets in the database, the application will <strong>timeout</strong> and hit a <strong>database connection limit</strong>.</p><h2 id="eager-loading-for-n1">Eager Loading for N+1</h2><p>There are several ways to implement eager loading on Ruby on Rails, the easiest one is to use the <a href="https://guides.rubyonrails.org/active_record_querying.html#includes">includes</a> method to specify the relationship that needs to be included in the result set.</p><p>Let&apos;s create a fix for the N+1 with the includes method:</p><figure class="kg-card kg-code-card"><pre><code class="language-ruby">Tweet.includes(:user).each do |post|
  puts &quot;#{tweet.title} was written by #{tweet.user.username}&quot;
end
</code></pre><figcaption>Eager Loading with includes method.</figcaption></figure><pre><code class="language-bash">Tweet Load (103.7ms)  SELECT &quot;tweets&quot;.* FROM &quot;tweets&quot;
  User Load (32.1ms)  SELECT &quot;users&quot;.* FROM &quot;users&quot; WHERE &quot;users&quot;.&quot;id&quot; IN (?, ?, ?, ?, ?)  [[&quot;id&quot;, 1], [&quot;id&quot;, 2]]
</code></pre><p>With the includes method, now we have a the same output but this time we are executing only 2 queries to load the data into memory. Even if we have 15,000 tweets on the database, this will only execute 2 queries!</p><h3 id="how-does-it-work">How does it work?</h3><p>What is happening is that <code>Tweet.includes(:user)</code><strong> </strong>is querying and retrieving the corresponding user records from the database immediately after the initial request for all tweets.</p><h3 id="using-scopes">Using Scopes</h3><p>Scopes are a powerful feature in Ruby on Rails that allow you to define reusable query fragments. Scopes can help you keep your code DRY (Don&apos;t Repeat Yourself) and make it easier to write complex queries.</p><p>For example, let&apos;s say we want to find all the posts that were created in the last week. We could write a scope like this:</p><pre><code class="language-ruby">class Tweet &lt; ApplicationRecord
  scope :recent, -&gt; { where(&quot;created_at &gt;= ?&quot;, 1.week.ago) }
end

# We can then use this scope in our code like this:
@tweets = Tweet.recent
</code></pre><p>This will return all the posts that were created in the last week. Scopes can be chained together to create more complex queries, like this:</p><pre><code class="language-ruby">@tweets = Tweet.recent.includes(:comments).order(created_at: :desc)</code></pre><p>This will return all the posts that were created in the last week, including their comments, and order them by creation date in descending order.</p><h3 id="use-database-indexes">Use database indexes</h3><p>Indexes are a way to optimize database queries by creating a data structure that allows the database to quickly find the data that it needs. In Ruby on Rails, you can create indexes by adding a migration that creates an index on a table.</p><hr><h2 id="resources">Resources</h2><figure class="kg-card kg-bookmark-card"><a class="kg-bookmark-container" href="https://guides.rubyonrails.org/active_record_querying.html"><div class="kg-bookmark-content"><div class="kg-bookmark-title">Active Record Query Interface &#x2014; Ruby on Rails Guides</div><div class="kg-bookmark-description">Active Record Query InterfaceThis guide covers different ways to retrieve data from the database using Active Record.After reading this guide, you will know: How to find records using a variety of methods and conditions. How to specify the order, retrieved attributes, grouping, and other properties&#x2026;</div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="https://guides.rubyonrails.org/images/favicon.ico" alt="Rails Query Optimization"><span class="kg-bookmark-author">Ruby on Rails Guides</span></div></div><div class="kg-bookmark-thumbnail"><img src="https://avatars.githubusercontent.com/u/4223" alt="Rails Query Optimization"></div></a></figure><figure class="kg-card kg-bookmark-card"><a class="kg-bookmark-container" href="https://apidock.com/rails/ActiveRecord/QueryMethods/includes"><div class="kg-bookmark-content"><div class="kg-bookmark-title">includes (ActiveRecord::QueryMethods) - APIdock</div><div class="kg-bookmark-description"></div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="https://apidock.com/images/favicon.ico" alt="Rails Query Optimization"><span class="kg-bookmark-author">APIdock</span></div></div><div class="kg-bookmark-thumbnail"><img src="https://d2vfyqvduarcvs.cloudfront.net/images/importance_3.png?1349367920" alt="Rails Query Optimization"></div></a></figure>]]></content:encoded></item><item><title><![CDATA[Modern CMake Workflow Part II]]></title><description><![CDATA[Part II of the modern cmake workflow series. This is my own approach to modern CMake using modular design and test-driven development.]]></description><link>https://hugomarquez.mx/modern-cmake-workflow-part-ii/</link><guid isPermaLink="false">623c5dd30e0bab33d837dee4</guid><category><![CDATA[CMake Workflow Series]]></category><category><![CDATA[CMake]]></category><category><![CDATA[C++]]></category><dc:creator><![CDATA[Hugo Márquez]]></dc:creator><pubDate>Fri, 25 Mar 2022 05:14:16 GMT</pubDate><media:content url="https://images.unsplash.com/photo-1531403009284-440f080d1e12?crop=entropy&amp;cs=tinysrgb&amp;fit=max&amp;fm=jpg&amp;ixid=MnwxMTc3M3wwfDF8c2VhcmNofDJ8fHdvcmtmbG93fGVufDB8fHx8MTY0ODEyMzUwNg&amp;ixlib=rb-1.2.1&amp;q=80&amp;w=2000" medium="image"/><content:encoded><![CDATA[<img src="https://images.unsplash.com/photo-1531403009284-440f080d1e12?crop=entropy&amp;cs=tinysrgb&amp;fit=max&amp;fm=jpg&amp;ixid=MnwxMTc3M3wwfDF8c2VhcmNofDJ8fHdvcmtmbG93fGVufDB8fHx8MTY0ODEyMzUwNg&amp;ixlib=rb-1.2.1&amp;q=80&amp;w=2000" alt="Modern CMake Workflow Part II"><p>Welcome to <strong>Part II</strong> of the modern CMake workflow series. In this post we will create a simple example of a small project which will help us to really grasp the concepts explained on <strong><a href="https://hugomarquez.mx/modern-cmake-workflow-part-i">Part I</a></strong>. Also I&apos;ll share this small project on a github repository which once cloned it will help you start a new C++ project with all the conventions mentioned in <strong><a href="https://hugomarquez.mx/modern-cmake-workflow-part-i">Part I</a></strong> in place.</p><h2 id="what-are-we-building">What are we building?</h2><p>OK so lets build a short and easy example of a module, something useful and not too complicated for the purpose of this blog post. For this example we will make a simple <strong>system module with a Logger</strong> which will be a private interface of the <strong>spdlog</strong> library.</p><p>To start building this module we will need the following:</p><ul><li>Create our module directory inside the <strong>src</strong> folder. The name of the parent folder will be our module&apos;s name in this example it will be called <strong>system</strong>.</li><li>Inside our module&apos;s directory we need to create the public header&apos;s directory and we will follow <strong>Part I</strong> naming conventions. So for our example we will use the <strong>pn</strong> namespace, which stands for project namespace, it will be as follows: <em>include/pn/system/.</em></li></ul><p>Here is an expanded view of the project&apos;s tree:</p><!--kg-card-begin: markdown--><p><img src="https://images2.imgbox.com/57/c2/Ehg3hb1J_o.jpg" alt="Modern CMake Workflow Part II" title="Expanded Project Structure" loading="lazy"></p>
<!--kg-card-end: markdown--><h3 id="the-system-module">The System Module</h3><p>We&apos;ll build a simple interface to the <strong>spdlog</strong> logger, we will start with a singleton pattern to build this feature. First we need a public header so other libraries that link to this module may be able to log to the console even though they won&apos;t have access to the <strong>spdlog</strong> library.</p><figure class="kg-card kg-code-card"><pre><code class="language-cpp">#pragma once

/**
 * Notice we didn&apos;t include the spdlog library here,
 * it was included in the source file so we can make it a
 * private dependency.
 * 
 * If you include a header of a dependency on a public library header,
 * then that dependency needs to be declared public as well.
 **/

#include &lt;string&gt;

namespace pn {
  class Logger {
    public:
      // Singleton Manager
      static Logger *getInstance()
      {
        if (instance == nullptr) {
          instance = new Logger();
          return instance;
        }
        return instance;
      }
      
      static void setLevel(int level);
      static void debug(std::string msg);
      static void info(std::string msg);
      static void warn(std::string msg);
      static void error(std::string msg);
      static void critical(std::string msg);
    
    private:
      Logger(){ setLevel(1);}
      static Logger *instance;
  };
}
</code></pre><figcaption>Logger.h</figcaption></figure><p>This is a simple header, we defined the Logger class which is a singleton with static methods, every method corresponds to the different types of logs <strong>spdlog</strong> has and each receives a string parameter as a message.</p><p>Now that we have our Logger specification it is time to write the implementation of it:</p><figure class="kg-card kg-code-card"><pre><code class="language-cpp">// Include our public library header
#include &lt;pn/system/Logger.h&gt;

/**
 * Notice we included spdlog here instead of the Logger header, 
 * this is because we want to make it a private dependency
 * 
 **/
#include &lt;spdlog/spdlog.h&gt;
#include &quot;spdlog/sinks/stdout_color_sinks.h&quot;

namespace pn {
  Logger* Logger::instance = 0;

  void Logger::setLevel(int level)
  {
    switch (level) {
      case 1: spdlog::set_level(spdlog::level::debug); break;
      default: spdlog::set_level(spdlog::level::debug); break;
    }
  }

  void Logger::debug(std::string msg) { spdlog::debug(msg);}
  void Logger::info(std::string msg) { spdlog::info(msg);}
  void Logger::warn(std::string msg) { spdlog::warn(msg);}
  void Logger::error(std::string msg) { spdlog::error(msg);}
  void Logger::critical(std::string msg) { spdlog::critical(msg);}
}
</code></pre><figcaption>Logger.cpp</figcaption></figure><p>The implementation is simple, we just instantiate our Logger object and refer every type of log to the corresponding <strong>spdlog</strong> function.</p><h3 id="the-main-executable">The Main Executable</h3><p>To create our main executable we first need to create a <strong>CMakeLists.txt</strong> where we will tell the build environment about it, add the subdirectory of the system module and link the main executable with our system library.</p><figure class="kg-card kg-code-card"><pre><code class="language-cmake"># Add modules
add_subdirectory(system)

# Create our main executable
add_executable(main main.cpp)

# Link privately our main executable with our shared libraries
target_link_libraries(main PRIVATE pn-system)
</code></pre><figcaption>src&apos;s CMakeLists.txt</figcaption></figure><p>And now the main executable with the main function which just calls each type of logs:</p><figure class="kg-card kg-code-card"><pre><code class="language-cpp">#include &quot;version.h&quot;

// Include system module&apos;s logger
#include &lt;pn/system/Logger.h&gt;

int main(int argc, char const *argv[]) {
  pn::Logger::setLevel(1);
  pn::Logger::info(PN_INFO);
  pn::Logger::debug(&quot;This is a debug log&quot;);
  pn::Logger::warn(&quot;Beware of this log!&quot;);
  pn::Logger::error(&quot;Oops something went wrong!&quot;);
  pn::Logger::critical(&quot;I&apos;m ded :(&quot;);
  return 0;
}
</code></pre><figcaption>main.cpp</figcaption></figure><p>You might have notice the version header, which is just a header with pre-processor functions defining the version and description of the project:</p><pre><code class="language-cpp">#pragma once
#include &lt;string&gt;

#define PN_VERSION_MAJOR 0
#define PN_VERSION_MINOR 0
#define PN_VERSION_PATCH 1

#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)

#define PN_VERSION &quot;v&quot; TOSTRING(PN_VERSION_MAJOR) &quot;.&quot; TOSTRING(PN_VERSION_MINOR) &quot;.&quot; TOSTRING(PN_VERSION_PATCH)
#define PN_NAME &quot;Project Name&quot;
#define PN_DESCRIPTION &quot;Project Description&quot;
#define PN_COPYRIGHT &quot;http://hugomarquez.mx \t (C) 2022&quot;

#define PN_INFO &quot;\n&quot; PN_NAME &quot;: &quot; PN_DESCRIPTION &quot;\n&quot; PN_VERSION &quot;\n&quot; PN_COPYRIGHT &quot;\n&quot;</code></pre><h2 id="test-driven-development">Test-Driven Development</h2><p>For our testing purposes we need to create a <strong>CMakeLists.txt</strong>, which its sole concern will be finding the testing framework library, the main testing executable with the linkage of our modules.</p><figure class="kg-card kg-code-card"><pre><code class="language-cmake"># Find required package/framework for testing
# In this case I&apos;ll be using Catch2
find_package(Catch2 REQUIRED)

# Create main test executable
add_executable(Test Test.cpp)

# Link with pn-system library
target_link_libraries(Test PRIVATE pn-system)

# Link with Catch2 testing framework
if(Catch2_FOUND)
  message(&quot;-- [TEST]: Required library Catch2 found!&quot;)
  set(Catch2_test_util &quot;${Catch2_LIB_DIRS}/cmake/Catch2&quot;)
  target_link_libraries(Test PRIVATE Catch2::Catch2)
endif(Catch2_FOUND)

include(CTest)
include(${Catch2_test_util}/Catch.cmake)
catch_discover_tests(Test)
</code></pre><figcaption>Test&apos;s CMakeLists.txt</figcaption></figure><p>And for our test executable we have the following example:</p><pre><code class="language-cpp">// This tells Catch to provide a main() - only do this in one cpp file
#define CATCH_CONFIG_MAIN
#include &lt;catch2/catch.hpp&gt;

// Here we include our system module&apos;s test following the directory naming convention
#include &quot;./pn/system/LoggerTest.h&quot;
</code></pre><p>Finally lets build our test! This will be very simple because our Logger class only refers the spdlog functions with static methods. So we only need to test that the singleton pattern is not returning a null or empty object.</p><figure class="kg-card kg-code-card"><pre><code class="language-cpp">#include &lt;string&gt;
#include &lt;catch2/catch.hpp&gt;
#include &lt;pn/system/Logger.h&gt;

using namespace pn;

TEST_CASE(&quot;pn::Logger&quot;, &quot;[System]&quot;) {
  
  SECTION(&quot;#getInstance()&quot;) {

    // Singleton pattern, shouldn&apos;t return 0
    REQUIRE(Logger::getInstance() != 0);
  }
}
</code></pre><figcaption>LoggerTest.h</figcaption></figure><h2 id="putting-it-all-together">Putting it all together!</h2><h3 id="getting-our-dependencies">Getting our dependencies</h3><p>To get our dependencies from conan we navigate to the build folder and run the following command:</p><pre><code class="language-bash">$ conan install ../</code></pre><p>This will download our dependencies and the modules required to find them using CMake:</p><!--kg-card-begin: markdown--><p><img src="https://images2.imgbox.com/f3/4f/Af6oEOz2_o.jpg" alt="Modern CMake Workflow Part II" title="Conan install example" loading="lazy"></p>
<!--kg-card-end: markdown--><h3 id="generating-and-compiling-our-build-files">Generating and compiling our build files</h3><p>To generate our build files, which in my case I&apos;ll be using <strong>makefiles</strong>, we need to run the cmake generator inside the build directory:</p><pre><code class="language-bash">$ cmake ../</code></pre><!--kg-card-begin: markdown--><p><img src="https://images2.imgbox.com/73/46/paLQE75w_o.jpg" alt="Modern CMake Workflow Part II" title="CMake generate example" loading="lazy"></p>
<!--kg-card-end: markdown--><h3 id="running-the-tests">Running the tests</h3><p>We have several options to run our tests, we can use <strong>CTest</strong> or just simply running the test executable, I&apos;m going to show both versions of it:</p><!--kg-card-begin: markdown--><p><img src="https://images2.imgbox.com/6d/15/18gGbGIp_o.jpg" alt="Modern CMake Workflow Part II" title="Testing Example" loading="lazy"></p>
<!--kg-card-end: markdown--><h3 id="running-our-main-executable">Running our main executable</h3><p>Finally it is time to run our main executable, when we run it we should see all our logs being displayed on the console:</p><!--kg-card-begin: markdown--><p><img src="https://images2.imgbox.com/99/b0/MhZCWMq8_o.jpg" alt="Modern CMake Workflow Part II" title="Main Execution" loading="lazy"></p>
<!--kg-card-end: markdown--><hr><p>Thank you for reading my post, it was a long journey but we had fun... right? Either way I really hope you found this helpful and I&apos;ll be leaving you with the github repository if you would like to use this as a template for your new C++ projects.</p><p>Bottoms up! &#x1F37B;</p><h2 id="resources">Resources</h2><figure class="kg-card kg-bookmark-card"><a class="kg-bookmark-container" href="https://github.com/gabime/spdlog"><div class="kg-bookmark-content"><div class="kg-bookmark-title">GitHub - gabime/spdlog: Fast C++ logging library.</div><div class="kg-bookmark-description">Fast C++ logging library. Contribute to gabime/spdlog development by creating an account on GitHub.</div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="https://github.com/fluidicon.png" alt="Modern CMake Workflow Part II"><span class="kg-bookmark-author">GitHub</span><span class="kg-bookmark-publisher">gabime</span></div></div><div class="kg-bookmark-thumbnail"><img src="https://opengraph.githubassets.com/8cc309e766bb1262a2efaee0b94fb0f3dcb0ce8ba9e89696745885c2d078557c/gabime/spdlog" alt="Modern CMake Workflow Part II"></div></a></figure><figure class="kg-card kg-bookmark-card"><a class="kg-bookmark-container" href="https://github.com/hugomarquez/Modern-CMake-Workflow"><div class="kg-bookmark-content"><div class="kg-bookmark-title">GitHub - hugomarquez/Modern-CMake-Workflow: Starter template or skeleton for test-driven and modular designed development using CMake and C++</div><div class="kg-bookmark-description">Starter template or skeleton for test-driven and modular designed development using CMake and C++ - GitHub - hugomarquez/Modern-CMake-Workflow: Starter template or skeleton for test-driven and modu...</div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="https://github.com/fluidicon.png" alt="Modern CMake Workflow Part II"><span class="kg-bookmark-author">GitHub</span><span class="kg-bookmark-publisher">hugomarquez</span></div></div><div class="kg-bookmark-thumbnail"><img src="https://opengraph.githubassets.com/8313b4c50ad4cf3fe015bb5b4fb8c097f30a68b59bc749c55d061571de21d6d5/hugomarquez/Modern-CMake-Workflow" alt="Modern CMake Workflow Part II"></div></a></figure>]]></content:encoded></item><item><title><![CDATA[Modern CMake Workflow Part I]]></title><description><![CDATA[This is my workflow on modern cmake using modular design and test-driven development.]]></description><link>https://hugomarquez.mx/modern-cmake-part-i/</link><guid isPermaLink="false">62354d090e0bab33d837da4e</guid><category><![CDATA[CMake Workflow Series]]></category><category><![CDATA[CMake]]></category><category><![CDATA[C++]]></category><dc:creator><![CDATA[Hugo Márquez]]></dc:creator><pubDate>Fri, 25 Mar 2022 04:13:46 GMT</pubDate><media:content url="https://images.unsplash.com/photo-1542744094-24638eff58bb?crop=entropy&amp;cs=tinysrgb&amp;fit=max&amp;fm=jpg&amp;ixid=MnwxMTc3M3wwfDF8c2VhcmNofDF8fHdvcmtmbG93fGVufDB8fHx8MTY0NzY2MDQwOQ&amp;ixlib=rb-1.2.1&amp;q=80&amp;w=2000" medium="image"/><content:encoded><![CDATA[<img src="https://images.unsplash.com/photo-1542744094-24638eff58bb?crop=entropy&amp;cs=tinysrgb&amp;fit=max&amp;fm=jpg&amp;ixid=MnwxMTc3M3wwfDF8c2VhcmNofDF8fHdvcmtmbG93fGVufDB8fHx8MTY0NzY2MDQwOQ&amp;ixlib=rb-1.2.1&amp;q=80&amp;w=2000" alt="Modern CMake Workflow Part I"><p>When I was learning a modern approach to CMake, I remember it was difficult! There were a lot of rules and sometimes those rules didn&apos;t make any sense unless there was an example of it. Another thing that hinder my learning curve of CMake was the vast amount of open source projects that uses &quot;old&quot; CMake.</p><p>To solve this and based on some of the resources I&apos;ve listed below, I developed a customized version on how to effectively use modern CMake on your C++ projects. Of course it goes without saying this is based on my own experience and things could be subject to change, besides I&apos;m encouraging to <strong>make your own changes</strong> to this workflow.</p><p>In <strong>Part I</strong> of this post, I&apos;ll make a brief introduction to modern CMake, what type of problems it tries to solve and how we can start using it. Then I&apos;ll recommend a project structure as a skeleton for new projects as well as some tools for dependencies. Finally some resources I consider fundamental to really understand how to use modern CMake. </p><p>As I stated above one of my biggest hinders was the lack of examples, so to be part of the solution in <strong><a href="https://hugomarquez.mx/modern-cmake-workflow-part-ii">Part II</a></strong> we&apos;ll make a small and simple example of a module as a shared library with a testing environment and private dependencies.</p><h2 id="what-is-modern-cmake">What is &quot;Modern CMake&quot;?</h2><p>CMake is a collection of open source tools that are designed to build, test and package software. It is used to control the compilation process through configuration files that generates native makefiles or workspaces that can be used to compile on the environment of choice. In short, CMake is not a build system, but a collection of tools that generates another system&apos;s build files.</p><p>CMake is constantly evolving and the most significant additions were released in version 3.0 which is what we called &quot;Modern CMake&quot;. Despite this constant evolution and benefits many software engineers and programmers are not using them due to the lack of knowledge or some sort of resistance to modernizing old code base.</p><p>To get started with modern CMake you need to update your installation to the latest version of CMake, and add to your <strong>CMakeLists.txt</strong> the minimum required version to 3.10 or above. Below is a minimal <strong>CMakeLists.txt</strong> file that you can use as a reference to in your CMake and C++ projects.</p><pre><code class="language-cmake">cmake_minimum_required(VERSION 3.10.2)

# Set version variables
set(version_major &quot;0&quot;)
set(version_minor &quot;0&quot;)
set(version_patch &quot;1&quot;)

# Set project version
set(project_version &quot;${version_major}.${version_minor}.${version_patch}&quot;)

# Set the project and description
project(ProjectName VERSION ${project_version} DESCRIPTION &quot;Project Name&quot; LANGUAGES CXX)

# Set custom cmake modules path
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} &quot;${CMAKE_SOURCE_DIR}/cmake/&quot;)

# Set output paths
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)

# Use c++11 flag for all modules
add_definitions(&quot;-std=c++11&quot;)

# Conan setup for dependencies
include(${CMAKE_BINARY_DIR}/conan_paths.cmake)

# Add sources
add_subdirectory(src)

# Testing
# PN stands for project namespace, change accordingly
option(PN_BUILD_TESTS &quot;Determines whether to build tests.&quot; ON)
if(PN_BUILD_TESTS)
  enable_testing()
  add_subdirectory(test)
endif(PN_BUILD_TESTS)
</code></pre><h2 id="thinking-in-modules">Thinking in Modules</h2><p>For example, imagine you&apos;re working on a delivery application similar to Uber Eats, you might have an architecture similar to this:</p><!--kg-card-begin: markdown--><p><img src="https://images2.imgbox.com/48/8b/Q7kewvrf_o.jpg" alt="Modern CMake Workflow Part I" title="Delivery example in theory" loading="lazy"></p>
<!--kg-card-end: markdown--><p>Where you have your modules separated by domains, in theory you can test and develop in isolation. This kinda looks OK, though we all know this is not going to be maintained and sooner than later we ended up with something like this:</p><!--kg-card-begin: markdown--><p><img src="https://images2.imgbox.com/c9/f7/l6fniXEB_o.jpg" alt="Modern CMake Workflow Part I" title="Delivery example in practice" loading="lazy"></p>
<!--kg-card-end: markdown--><p>In practice, we ended up mixing and matching our modules, soon the route calculator module will be requiring the prices serializer and the order serializer modules as dependencies and as a result their dependencies and compilation flags. So what do we do? the typical solution is to group those modules.</p><!--kg-card-begin: markdown--><p><img src="https://images2.imgbox.com/5e/7f/P3y2xWVj_o.jpg" alt="Modern CMake Workflow Part I" title="Delivery example combined" loading="lazy"></p>
<!--kg-card-end: markdown--><p>And more grouping needed in the client&apos;s orders and fare modules:</p><!--kg-card-begin: markdown--><p><img src="https://images2.imgbox.com/cd/09/NJcLsKPO_o.jpg" alt="Modern CMake Workflow Part I" title="Delivery example more combinations" loading="lazy"></p>
<!--kg-card-end: markdown--><p>But the problem with this &quot;solution&quot; is that we ended up with a big monolithic code base, with a compilation nightmare where updating or changing one dependency affects modules who don&apos;t even directly use that dependency so we ended up declaring every dependency as public &#x1F922;. </p><p>If you need a more in depth example,<strong> Mathieu Ropert</strong> talked about the benefits and patterns that can be used for modular design using CMake in his <a href="https://www.youtube.com/watch?v=eC9-iRN2b04">CppCon 2017</a>. I highly recommend watching Ropert&apos;s talk.</p><h3 id="so-what-is-the-real-solution-then">So what is the &quot;real&quot; solution then?</h3><p>I believe a solution to this problem is to force ourselves to a module oriented way of thinking by creating <strong>shared libraries</strong> whose purpose are very specific to a certain domain. To achieve this with modern CMake we need to use the target specific commands, to learn more about this I recommend <a href="https://kubasejdak.com/modern-cmake-is-like-inheritance">Kuba Sejdak&apos;s blog post</a> on targets and properties. </p><p>Using this approach will allow us test and develop software on isolation and without affecting other modules. Of course there should be a judgment call on whether a certain module should include more or less since there is a limit to what can be tested and developed on isolation.</p><h2 id="project-structure-convention">Project Structure Convention</h2><p>Now that we have the modular design mindset, it&apos;s time to propose a simple structure for our projects, this will help us maintain a modular design mindset and our test driven development. We can start our project tree with the following folders and files:</p><!--kg-card-begin: markdown--><p><img src="https://images2.imgbox.com/e4/1a/6ZIwVqwm_o.jpg" alt="Modern CMake Workflow Part I" title="Root Project Structure" loading="lazy"></p>
<!--kg-card-end: markdown--><ul><li><strong>Build:</strong> This is required by CMake, it is the place where the build files will be created, it might be a Makefile, etc.</li><li><strong>Docs:</strong> We should always document our projects, if you use a documentation generator like Doxygen, then this is the place where it should generate the docs.</li><li><strong>Lib:</strong> Here we might store 3rd party libraries that were not available through Conan, it can be a git submodule.</li><li><strong>CMakeLists.txt:</strong> This is our entry point in the build process, you can start by using our example shown above.</li><li><strong>conanfile.txt:</strong> Our Conan file where we declare our dependencies, similar to npm and package.json.</li></ul><h3 id="the-src-directory">The src directory</h3><p>The source directory is the place where we put our sources, headers and modules. It should also contain our main entry point via an executable or library. The modules inside this directory should follow a simple convention:</p><ul><li>The module&apos;s name is the root folder of that module&apos;s directory.</li><li>Every module should include a CMakeLists.txt, where it will be declared as a target library or executable as well as all its dependencies and compilation flags.</li><li>The public headers of a module should reside in the following structure: <em>include/{namespace}/{module&apos;s name}/</em>.</li><li>The private headers and sources of a module should reside inside the root directory of that module.</li><li>Always link to a dependency as private unless it is necessary to explicitly make it public.</li></ul><h3 id="the-test-directory">The test directory</h3><p>This is where we put or tests, but we need some structure as well. For our test&apos;s directory we need to use the following convention:</p><ul><li>Tests for the main executable should be put in the test&apos;s root directory.</li><li>Every module&apos;s test should use this structure: <em>test/{namespace}/{module&apos;s name}/.</em></li><li>Include the module&apos;s test headers in the test executable.</li></ul><h2 id="dependencies-and-package-managers">Dependencies and Package Managers</h2><p>For dependencies and packages management I like to use <a href="https://conan.io/">Conan</a>. With this tool you just specify what package or library you need for your project on a <strong>conanfile.txt</strong> and Conan will be in charge of downloading the appropriate sources and headers.</p><p>To search for the available packages and their versions we need the <a href="https://conan.io/center/">ConanCenter</a>, which is a repository where people share C/C++ packages. There we can search for a package and choose an appropriate version to use on our projects.</p><figure class="kg-card kg-code-card"><pre><code class="language-bash">[requires]
spdlog/1.4.2
catch2/2.13.7

[generators]
cmake_paths
cmake_find_package
</code></pre><figcaption>conanfile.txt example</figcaption></figure><p>Conan is more complex than this, but for our purposes this is enough. Also it is worth noting that there are other solutions available like <a href="https://vcpkg.io/en/index.html">vcpkg</a> and/or just using your default package manager like apt, pacman or yum.</p><div class="kg-card kg-callout-card kg-callout-card-yellow"><div class="kg-callout-emoji">&#x2139;&#xFE0F;</div><div class="kg-callout-text">If you use your system&apos;s default package manager keep in mind that all packages will be installed in your computer, which might make a complex task to upgrade packages in your project.</div></div><p>To add a dependency to a module, we need to link that module with the library. Fortunately CMake has modules to help us find those libraries and with Conan this is easier. Next an example based on the upcoming <strong><a href="https://hugomarquez.mx/modern-cmake-workflow-part-ii">Part II</a></strong>, on how to search and link to a library on CMake:</p><figure class="kg-card kg-code-card"><pre><code class="language-cmake"># Create our shared library and include the sources
add_library(pn-system SHARED 
  Logger.cpp
)

# Dependencies and compilation flags for this library
# Find spdlog
find_package(spdlog REQUIRED)
if(spdlog_FOUND)
  message(STATUS &quot;[SYSTEM][BUILD]: Required library spdlog found!&quot;)

  # Link to the spdlog library as a private dependency, this means
  # that if another module links to the pn-system library it 
  # won&apos;t be able to access the spdlog library.
  target_link_libraries(pn-system PRIVATE spdlog::spdlog)
endif(spdlog_FOUND)
</code></pre><figcaption>Link a dependency</figcaption></figure><h2 id="whats-next">What&apos;s next?</h2><p>For <strong><a href="https://hugomarquez.mx/modern-cmake-workflow-part-ii">Part II</a> </strong>and the last part of this series, we will use the above knowledge to create a simple module example using modern CMake, private dependencies, naming conventions and a basic structure to start our test-driven development process. </p><p>I know all this information may be a little daunting and confusing, hopefully on <strong><a href="https://hugomarquez.mx/modern-cmake-workflow-part-ii">Part II</a></strong> this makes more sense and leads you to a happy relationship with this amazing tools.</p><hr><h2 id="resources">Resources</h2><h3 id="cmake-is-complex-but-there-is-hope">CMake is complex, but there is hope!</h3><p>Learning and using CMake can be a daunting task, especially when you can find out in the wild &quot;old&quot; and &quot;modern&quot; CMake that might confuse you, but fortunately for us there are a lot of great resources by people who are really passionate on build systems and CMake. I would like to recommend some awesome resources to get you started with this enterprise.</p><figure class="kg-card kg-bookmark-card kg-card-hascaption"><a class="kg-bookmark-container" href="https://cmake.org/"><div class="kg-bookmark-content"><div class="kg-bookmark-title">CMake</div><div class="kg-bookmark-description"></div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="https://cmake.org/wp-content/uploads/2019/05/cropped-cmake_512-270x270.png" alt="Modern CMake Workflow Part I"><span class="kg-bookmark-author">CMake</span></div></div><div class="kg-bookmark-thumbnail"><img src="https://cmake.org/wp-content/uploads/2018/11/cmake_logo_slider.png" alt="Modern CMake Workflow Part I"></div></a><figcaption>The official documentation and guides</figcaption></figure><figure class="kg-card kg-bookmark-card kg-card-hascaption"><a class="kg-bookmark-container" href="https://kubasejdak.com/modern-cmake-is-like-inheritance"><div class="kg-bookmark-content"><div class="kg-bookmark-title">Modern CMake is like inheritance - Kuba Sejdak</div><div class="kg-bookmark-description">CMake has been created in 2000 by Bill Hoffman from Kitware. During the last 20 years, as of the time of&#xA0;this publication, it&#x2019;s been constantly evolving by adding new features and expanding its support for third-party libraries. But the most significant additions were released in version 3.0 and are&#x2026;</div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="https://i1.wp.com/kubasejdak.com/wp-content/uploads/2020/06/cropped-favicon-e1591387224411-1.png?fit=192%2C192&amp;ssl=1" alt="Modern CMake Workflow Part I"><span class="kg-bookmark-author">Kuba Sejdak</span><span class="kg-bookmark-publisher">Kuba Sejdak</span></div></div><div class="kg-bookmark-thumbnail"><img src="https://i2.wp.com/kubasejdak.com/wp-content/uploads/2020/01/Modern_CMake_is_like_inheritance.png?fit=1600%2C800&amp;ssl=1" alt="Modern CMake Workflow Part I"></div></a><figcaption>Super awesome blog post on modern CMake</figcaption></figure><figure class="kg-card kg-bookmark-card kg-card-hascaption"><a class="kg-bookmark-container" href="https://mropert.github.io/2017/10/14/modern_cmake_video/"><div class="kg-bookmark-content"><div class="kg-bookmark-title">My CppCon 2017 talk about Modular Design with CMake is online! &#xB7; Mathieu Ropert</div><div class="kg-bookmark-description">Do you think about your libraries in CMake in term of compiler flags or architecture modules? In this talk, I show you how to do the latter.</div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="https://mropert.github.io/apple-touch-icon.png" alt="Modern CMake Workflow Part I"><span class="kg-bookmark-publisher">C++ French User Group (CppFRUG)</span></div></div><div class="kg-bookmark-thumbnail"><img src="https://avatars2.githubusercontent.com/u/101672" alt="Modern CMake Workflow Part I"></div></a><figcaption>Amazing CppCon on modular design using modern CMake</figcaption></figure><figure class="kg-card kg-bookmark-card kg-card-hascaption"><a class="kg-bookmark-container" href="https://cliutils.gitlab.io/modern-cmake/"><div class="kg-bookmark-content"><div class="kg-bookmark-title">An Introduction to Modern CMake &#xB7; Modern CMake</div><div class="kg-bookmark-description"></div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="https://cliutils.gitlab.io/modern-cmake/gitbook/images/apple-touch-icon-precomposed-152.png" alt="Modern CMake Workflow Part I"><span class="kg-bookmark-publisher">Henry Schreiner</span></div></div></a><figcaption>Github open book on modern CMake</figcaption></figure><figure class="kg-card kg-bookmark-card kg-card-hascaption"><a class="kg-bookmark-container" href="https://gist.github.com/mbinna/c61dbb39bca0e4fb7d1f73b0d66a4fd1"><div class="kg-bookmark-content"><div class="kg-bookmark-title">Effective Modern CMake</div><div class="kg-bookmark-description">Effective Modern CMake. GitHub Gist: instantly share code, notes, and snippets.</div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="https://gist.github.com/fluidicon.png" alt="Modern CMake Workflow Part I"><span class="kg-bookmark-author">Gist</span><span class="kg-bookmark-publisher">262588213843476</span></div></div><div class="kg-bookmark-thumbnail"><img src="https://github.githubassets.com/images/modules/gists/gist-og-image.png" alt="Modern CMake Workflow Part I"></div></a><figcaption>General Guidelines on the effective use of modern CMake</figcaption></figure>]]></content:encoded></item><item><title><![CDATA[Simple CSS Grid inspired by bootstrap]]></title><description><![CDATA[I'm too lazy to extract bootstrap grid or to run NPM to install another library, let's fix that!]]></description><link>https://hugomarquez.mx/simple-css-grid/</link><guid isPermaLink="false">623274e90e0bab33d837d809</guid><category><![CDATA[CSS]]></category><category><![CDATA[Bootstrap]]></category><dc:creator><![CDATA[Hugo Márquez]]></dc:creator><pubDate>Thu, 17 Mar 2022 02:21:52 GMT</pubDate><media:content url="https://images.unsplash.com/photo-1581273154768-0a9a16887d2a?crop=entropy&amp;cs=tinysrgb&amp;fit=max&amp;fm=jpg&amp;ixid=MnwxMTc3M3wwfDF8c2VhcmNofDExfHxncmlkfGVufDB8fHx8MTY0NzQ4NjcyMg&amp;ixlib=rb-1.2.1&amp;q=80&amp;w=2000" medium="image"/><content:encoded><![CDATA[<img src="https://images.unsplash.com/photo-1581273154768-0a9a16887d2a?crop=entropy&amp;cs=tinysrgb&amp;fit=max&amp;fm=jpg&amp;ixid=MnwxMTc3M3wwfDF8c2VhcmNofDExfHxncmlkfGVufDB8fHx8MTY0NzQ4NjcyMg&amp;ixlib=rb-1.2.1&amp;q=80&amp;w=2000" alt="Simple CSS Grid inspired by bootstrap"><p>Imagine this scenario, you are working on a web development project, maybe they&apos;re using &quot;insert trending CSS framework here&quot;, and you just want to try out some simple cool new &quot;glitch&quot; effect on the User&apos;s profile. So you decided: <em>&quot;Ok, let&apos;s spin up a simple &#xA0;starter page to try out this new feature&quot;</em>. You clone a starter repository with everything you need, but wait... do you really need everything? How about we just simply copy-paste a <strong>4Kb</strong> file to <strong>style.css</strong> and start developing that new feature!</p><h2 id="css-variables">CSS Variables</h2><p>Yes! you can use variables in CSS without using a pre-processor like SASS and LESS. It is very simple and if you want to learn more about them I&apos;d recommend the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties">Mozilla reference guide on CSS variables</a>. For now our variables will be very simple, let&apos;s start with our breakpoints.</p><figure class="kg-card kg-code-card"><pre><code class="language-css">/* Variables */

:root {
  /* Breakpoints */
  --mobile: 576px;
  --tablet: 768px;
  --desktop: 992px;
  --desktop-lg: 1200px;
}</code></pre><figcaption>Media query breakpoints</figcaption></figure><p>We also need to configure our grid system, the number of columns, the gutter size (space between columns), types of columns and their minimal widths. For now let&apos;s add the columns and the gutter to the root&apos;s variables.</p><figure class="kg-card kg-code-card"><pre><code class="language-css">/* Variables */

:root {
  /* Breakpoints */
  --mobile: 576px;
  --tablet: 768px;
  --desktop: 992px;
  --desktop-lg: 1200px;
  /* Grid Config */
  --grid-columns: 12;
  --grid-gutter: 15px;
}</code></pre><figcaption>Grid configuration</figcaption></figure><h2 id="container">Container</h2><p>The container or sometimes called wrapper is our fundamental block, this is the place where all the rows and columns will live. In our simple implementation, we only need to define the horizontal padding, that is the left and right padding.</p><figure class="kg-card kg-code-card"><pre><code class="language-css">.container {
  width: 100%;
  padding-left: var(--grid-gutter);
  padding-right: var(--grid-gutter);
  margin-left: auto;
  margin-right: auto;
}</code></pre><figcaption>The container</figcaption></figure><h3 id="responsive-containers">Responsive Containers</h3><p>For a more &quot;modern&quot; approach to our containers, we will set our containers to a different maximum width depending on the device&apos;s screen minimum width. To achieve this, we need to make use of media queries, which are useful when you want to modify your site depending on a device&apos;s specific characteristics such as screen resolution or browser <a href="https://developer.mozilla.org/en-US/docs/Glossary/Viewport">viewport</a> width. You can read more about this on the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries">Mozilla reference guide</a> on media queries.</p><figure class="kg-card kg-code-card"><pre><code class="language-css">/* Responsive Containers */

@media (min-width: 576px) {
  .container {
    max-width: 540px;
  }
}

@media (min-width: 768px) {
  .container {
    max-width: 720px;
  }
}

@media (min-width: 992px) {
  .container {
    max-width: 960px;
  }
}

@media (min-width: 1200px) {
  .container {
    max-width: 1140px;
  }
}</code></pre><figcaption>The Responsive Container</figcaption></figure><h2 id="rows">Rows</h2><p>The rows will be a bit more complex, it will use the <a href="https://css-tricks.com/snippets/css/complete-guide-grid/">CSS Grid Layout System</a> which is a 2D grid-based layout system. According to <a href="https://css-tricks.com/">CSS Tricks</a>, as of March 2017 all mayor browsers support this CSS feature including Android and IOS.</p><figure class="kg-card kg-code-card"><pre><code class="language-css">.row {
  display: grid;
  grid-template-columns: repeat(var(--grid-columns), 1fr);
  grid-gap: var(--grid-gutter);
  padding-top: .2em;
  padding-bottom: .2em;
}

.row&gt;* {
  box-sizing: border-box;
  flex-shrink: 0;
  width: 100%;
  max-width: 100%;
}

/* Hide something */
.d-none {
  display: none !important;
}</code></pre><figcaption>The Row</figcaption></figure><h2 id="columns">Columns</h2><p>This bit of our simple grid layout is pretty straightforward although a bit repetitive since we are not using a pre-processor like SASS or LESS. The idea is to define the positioning and padding of our columns then apply through media queries the responsive behavior.</p><figure class="kg-card kg-code-card"><pre><code class="language-css">/* -- Columns -- */

.col-sm-1,.col-sm-2,.col-sm-3,.col-sm-4,.col-sm-5,.col-sm-6,.col-sm-7,.col-sm-8,.col-sm-9,.col-sm-10,.col-sm-11,.col-sm-12,.col-sm,
.col-md-1,.col-md-2,.col-md-3,.col-md-4,.col-md-5,.col-md-6,.col-md-7,.col-md-8,.col-md-9,.col-md-10,.col-md-11,.col-md-12,.col-md,
.col-lg-1,.col-lg-2,.col-lg-3,.col-lg-4,.col-lg-5,.col-lg-6,.col-lg-7,.col-lg-8,.col-lg-9,.col-lg-10,.col-lg-11,.col-lg-12,.col-lg,
.col-xl-1,.col-xl-2,.col-xl-3,.col-xl-4,.col-xl-5,.col-xl-6,.col-xl-7,.col-xl-8,.col-xl-9,.col-xl-10,.col-xl-11,.col-xl-12,.col-xl,
.col {
  max-width: 100%;
  position: relative;
  padding-right: var(--grid-gutter);
  padding-left: var(--grid-gutter);
}</code></pre><figcaption>The Columns</figcaption></figure><h3 id="responsive-columns">Responsive Columns</h3><p>With our columns defined, now we need to define the behavior depending on the media query. As an example I will write and explain the first types of columns which are the <strong>col-sm-*</strong> for the small media query.</p><figure class="kg-card kg-code-card"><pre><code class="language-css">/* SM */

@media (min-width: 576px) {
  .col-sm-1 {
    grid-column: span 1;
  }
  .col-sm-2 {
    grid-column: span 2;
  }
  .col-sm-3 {
    grid-column: span 3;
  }
  .col-sm-4 {
    grid-column: span 4;
  }
  .col-sm-5 {
    grid-column: span 5;
  }
  .col-sm-6 {
    grid-column: span 6;
  }
  .col-sm-7 {
    grid-column: span 7;
  }
  .col-sm-8 {
    grid-column: span 8;
  }
  .col-sm-9 {
    grid-column: span 9;
  }
  .col-sm-10 {
    grid-column: span 10;
  }
  .col-sm-11 {
    grid-column: span 11;
  }
  .col-sm-12 {
    grid-column: span 12;
  }
}</code></pre><figcaption>The Responsive Columns</figcaption></figure><p>The idea here is to span the column count by 1 until we get to the 12th column. Now we need to do this to all the types of columns and media queries we&apos;re going to use, but for simplicity sake I&apos;ve already written it down for you!</p><h2 id="example">Example</h2><p>Just copy-paste the whole thing to a grid.css named file and reference it from your html like this.</p><figure class="kg-card kg-code-card"><pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;

&lt;head&gt;
  &lt;meta charset=&quot;UTF-8&quot;&gt;
  &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;
  &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
  &lt;title&gt;Vanilla CSS Grid Inspride by bootstrap&lt;/title&gt;
  &lt;link rel=&quot;stylesheet&quot; href=&quot;grid.css&quot;&gt;

&lt;/head&gt;

&lt;body&gt;
  &lt;div class=&quot;container&quot;&gt;
    &lt;div class=&quot;row&quot;&gt;
      &lt;div class=&quot;col-xl-6&quot;&gt;One of three columns&lt;/div&gt;
      &lt;div class=&quot;col-xl-4&quot;&gt;One of three columns&lt;/div&gt;
      &lt;div class=&quot;col&quot;&gt;One of three columns&lt;/div&gt;
    &lt;/div&gt;
    &lt;div class=&quot;row&quot;&gt;
      &lt;div class=&quot;col-sm-6 col-md-6 col-lg-6 col-xl-6&quot;&gt;One of three columns&lt;/div&gt;
      &lt;div class=&quot;col-sm-4 col-md-4 col-lg-4 col-xl-4&quot;&gt;One of three columns&lt;/div&gt;
      &lt;div class=&quot;col-sm-2 col-md-2 col-lg-2 col-xl-2&quot;&gt;One of three columns&lt;/div&gt;
    &lt;/div&gt;
    &lt;div class=&quot;row&quot;&gt;
      &lt;div class=&quot;col-sm-2 col-md-2 col-lg-2 col-xl-2&quot;&gt;One of three columns&lt;/div&gt;
      &lt;div class=&quot;col-sm-8 col-md-8 col-lg-8 col-xl-8&quot;&gt;One of three columns&lt;/div&gt;
      &lt;div class=&quot;col-sm-2 col-md-2 col-lg-2 col-xl-2&quot;&gt;One of three columns&lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/body&gt;

&lt;/html&gt;</code></pre><figcaption>Example 1</figcaption></figure><p>And here you can see the grid. (I added a dotted outline so you can see the different blocks of the grid layout)</p><!--kg-card-begin: markdown--><p><img src="https://images2.imgbox.com/7d/f4/PNHpx1y9_o.png" alt="Simple CSS Grid inspired by bootstrap" title="Simple Grid Example" loading="lazy"></p>
<!--kg-card-end: markdown--><h2 id="the-whole-thing">The whole thing</h2><!--kg-card-begin: html--><script src="https://gist.github.com/hugomarquez/b4978eac4c07e4407935785e52f75bd7.js"></script><!--kg-card-end: html--><h2 id="conclusion">Conclusion</h2><p>I&apos;m too lazy to get the extracted grid layout system from bootstrap or to run NPM and install another library, I just wanted a simple solution to test things out quickly and with less of a hassle than the other alternatives. So now, all I have to do is copy paste the file above. Hope you like it! Please tell me if you would like to add something or remove something to it.</p><p>Cheers! &#x1F37B;</p><hr><h2 id="references">References</h2><figure class="kg-card kg-bookmark-card"><a class="kg-bookmark-container" href="https://css-tricks.com/snippets/css/complete-guide-grid/"><div class="kg-bookmark-content"><div class="kg-bookmark-title">A Complete Guide to Grid | CSS-Tricks</div><div class="kg-bookmark-description">Our comprehensive guide to CSS grid, focusing on all the settings both for the grid parent container and the grid child elements.</div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="https://i0.wp.com/css-tricks.com/wp-content/uploads/2021/07/star.png?fit=180%2C180&amp;ssl=1" alt="Simple CSS Grid inspired by bootstrap"><span class="kg-bookmark-author">CSS-Tricks</span><span class="kg-bookmark-publisher">Chris House</span></div></div><div class="kg-bookmark-thumbnail"><img src="https://css-tricks.com/wp-json/social-image-generator/v1/image/343682" alt="Simple CSS Grid inspired by bootstrap"></div></a></figure><figure class="kg-card kg-bookmark-card"><a class="kg-bookmark-container" href="https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries"><div class="kg-bookmark-content"><div class="kg-bookmark-title">Using media queries - CSS: Cascading Style Sheets | MDN</div><div class="kg-bookmark-description">Media queries are useful when you want to modify your site or app depending on a device&#x2019;s general type (such as print vs. screen) or specific characteristics and parameters (such as screen resolution or browser viewport width).</div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="https://developer.mozilla.org/favicon-48x48.cbbd161b.png" alt="Simple CSS Grid inspired by bootstrap"><span class="kg-bookmark-author">MDN</span></div></div><div class="kg-bookmark-thumbnail"><img src="https://developer.mozilla.org/mdn-social-share.cd6c4a5a.png" alt="Simple CSS Grid inspired by bootstrap"></div></a></figure><figure class="kg-card kg-bookmark-card"><a class="kg-bookmark-container" href="https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties"><div class="kg-bookmark-content"><div class="kg-bookmark-title">Using CSS custom properties (variables) - CSS: Cascading Style Sheets | MDN</div><div class="kg-bookmark-description">Custom properties (sometimes referred to as CSS variables or cascading variables) are entities defined by CSS authors that contain specific values to be reused throughout a document. They are set using custom property notation (e.g., --main-color: black;) and are accessed using the var() function (e&#x2026;</div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="https://developer.mozilla.org/favicon-48x48.cbbd161b.png" alt="Simple CSS Grid inspired by bootstrap"><span class="kg-bookmark-author">MDN</span></div></div><div class="kg-bookmark-thumbnail"><img src="https://developer.mozilla.org/mdn-social-share.cd6c4a5a.png" alt="Simple CSS Grid inspired by bootstrap"></div></a></figure>]]></content:encoded></item><item><title><![CDATA[Linux unfreeze guide]]></title><description><![CDATA[What should we do when our computer's GUI freezes in Linux?]]></description><link>https://hugomarquez.mx/linux-unfreeze-guide/</link><guid isPermaLink="false">622d16ac0e0bab33d837d477</guid><category><![CDATA[Linux]]></category><dc:creator><![CDATA[Hugo Márquez]]></dc:creator><pubDate>Mon, 14 Mar 2022 04:16:51 GMT</pubDate><media:content url="https://images.unsplash.com/photo-1621252179027-94459d278660?crop=entropy&amp;cs=tinysrgb&amp;fit=max&amp;fm=jpg&amp;ixid=MnwxMTc3M3wwfDF8c2VhcmNofDF8fGFuZ3J5JTIwY29tcHV0ZXJ8ZW58MHx8fHwxNjQ3MTIzMzIz&amp;ixlib=rb-1.2.1&amp;q=80&amp;w=2000" medium="image"/><content:encoded><![CDATA[<h3 id="lets-face-it-this-isnt-as-obvious-as-ctrlaltdelete">Let&apos;s face it, this isn&apos;t as obvious as Ctrl+Alt+Delete.</h3><img src="https://images.unsplash.com/photo-1621252179027-94459d278660?crop=entropy&amp;cs=tinysrgb&amp;fit=max&amp;fm=jpg&amp;ixid=MnwxMTc3M3wwfDF8c2VhcmNofDF8fGFuZ3J5JTIwY29tcHV0ZXJ8ZW58MHx8fHwxNjQ3MTIzMzIz&amp;ixlib=rb-1.2.1&amp;q=80&amp;w=2000" alt="Linux unfreeze guide"><p>Have you been working on something very important, maybe it&apos;s a time critical commit that needs to be pushed <em>ASAP</em> while you are executing a CPU intensive task on the background and suddenly everything freezes and stops working?</p><p>Whatever the case it may be, we&apos;ve all been there and it&apos;s not as obvious on how to release our machines from that perpetual state of unresponsiveness. This is a simple guide on how to unfreeze our Linux machines from that state.</p><h3 id="processes-processes-everywhere">Processes, Processes Everywhere!</h3><!--kg-card-begin: markdown--><p><a href="https://imgflip.com/i/68g55r"><img src="https://i.imgflip.com/68g55r.jpg" title="made at imgflip.com" alt="Linux unfreeze guide"></a></p>
<!--kg-card-end: markdown--><p>The most common way of unfreezing your machine is by killing the process or parent process that is giving you trouble. Of course this will discard any unsaved data in that program and programs spawned by it. </p><h3 id="i-barely-have-control-%F0%9F%98%85">I barely have control &#x1F605;</h3><p>Assuming you have control on the machine. If you do, you could try the following:</p><ol><li><strong>Ctrl+Alt+t</strong> to open up a new terminal emulator.</li><li>On the terminal run <strong>ps aux</strong> to list all processes on the terminal.</li><li>Pipe it into a grep command to &quot;search&quot; for the process name.</li></ol><p>For example:</p><pre><code class="language-bash">$ ps aux | grep chrom
hugomar+    7670  2.5  5.2 17385448 317052 ?     Sl   Mar11  35:18 /opt/google/chrome/chrome --enable-crashpad
hugomar+    7677  0.0  0.0 16798672 2604 ?       Sl   Mar11   0:00 /opt/google/chrome/chrome_crashpad_handler --monitor-self --monitor-self-annotation=ptype=crashpad-handler --database=/home/hugomarquez/.config/google-chrome/Crash Reports --url=https://clients2.google.com/cr/report --annotation=channel= --annotation=lsb-release=Debian GNU/Linux 11 (bullseye) --annotation=plat=Linux --annotation=prod=Chrome_Linux --annotation=ver=97.0.4692.99 --initial-client-fd=5 --shared-client-connection
</code></pre><p>Find the parent process and kill it!</p><pre><code class="language-bash">$ kill 7670
</code></pre><p>Where <strong>7670</strong> is the process&apos;s ID, this will kill this process and all of its children, which will lead to closing the google chrome program on this example.</p><h5 id="the-kill-command-%F0%9F%92%80">The Kill Command &#x1F480;</h5><p>The kill command is used to send a signal to a process, the default signal for kill is <strong>TERM</strong>. If you need more information on this command and how to make a force kill, remember you always have man on your side.</p><div class="kg-card kg-callout-card kg-callout-card-blue"><div class="kg-callout-emoji">&#x2139;&#xFE0F;</div><div class="kg-callout-text">Remember to read the system reference manual of kill</div></div><pre><code class="language-bash">$ man kill
</code></pre><h3 id="some-form-of-control-%F0%9F%98%A5">Some form of control &#x1F625;</h3><p>If you move your cursor or pointer and it moves, you might still have some form of control over the machine, you could try to <strong>xkill</strong> the process that is giving you trouble. <strong>xkill</strong> is a command that kills a client process by its X resource and it is a utility for forcing the X server to close connections to a client.</p><p>To use this utility, try to open up a terminal emulator with <strong>Ctrl+Alt+t</strong> and type <strong>xkill</strong>, the mouse pointer will change to an icon of a skull and crossbones, and the next window you click will be killed. It is worth mentioning that in KDE you can run <strong>xkill</strong> with <strong>Ctrl+Alt+Esc</strong> by default. On GNOME you can create your own macro to run the <strong>xkill</strong> command.</p><!--kg-card-begin: markdown--><p><img src="https://images2.imgbox.com/59/9d/dLTemPfg_o.png" alt="Linux unfreeze guide" title="xkill example" loading="lazy"></p>
<!--kg-card-end: markdown--><h3 id="no-control-at-all-%F0%9F%98%B1">No control at all &#x1F631;</h3><p>So you have tried <strong>Ctrl+Alt+t</strong> to open up a terminal emulator and... nothing happens. If this is your case, your Desktop Environment might be unresponsive as well, where your cursor doesn&apos;t move and your key presses seems to do nothing at all. You might be thinking &quot;aagh maybe is time for a hard reset &#x1F922;&quot;, but I&apos;m here to tell you there might be another way.</p><h5 id="tty">TTY</h5><p>TTY has a complex history going back to <a href="https://en.wikipedia.org/wiki/Teleprinter">1800&apos;s</a>, but for our concerns it is worth to know that TTY stands for teletype and it is an abstract device in Linux. It might refer to a physical input device or to a virtual teletype where it allows users to interact with the system. We can see all the ttys in our system by cycling through tty1 to tty7, to do this we use the following commands <strong>Ctrl+Alt+F1</strong> to <strong>Ctrl+Alt+F7</strong>.</p><p>If you do this you might have notice that tty1 is used to display logs and tty7 is used to run the desktop environment, that leaves us with tty2 to tty6 to try to find and kill the process that is giving you trouble. Try going to tty2, log in with your credentials and apply the ps and grep combo seen above.</p><h3 id="the-last-resort-%F0%9F%98%AD">The Last Resort &#x1F62D;</h3><p>If you have tried the above methods with no success, you might still have some sort of communication with the kernel. It might be time to use <strong>SysRq</strong> key in combination with the following to perform a reset:</p><!--kg-card-begin: markdown--><ol>
<li>Press <strong>Ctrl+Alt+F2</strong> to switch to tty2.</li>
<li>Press <strong>Alt+SysRq+R</strong> to get the keyboard.</li>
<li>If pressing <strong>Ctrl+Alt+F2</strong> before failed, try it again now.</li>
<li>Press <strong>Alt+SysRq+E</strong> to term all processes.</li>
<li>Press <strong>Alt+SysRq+I</strong> to kill all processes.</li>
<li>Press <strong>Alt+SysRq+S</strong> to sync your disks.</li>
<li>Wait for OK or Done message.</li>
<li>Press <strong>Alt+SysRq+U</strong> to umount all disk drives.</li>
<li>Wait for OK or Done message.</li>
<li>Press <strong>Alt+SysRq+B</strong> to reboot.</li>
</ol>
<!--kg-card-end: markdown--><p>The letters REISUB is a mnemonic for <em>Reboot Even If System Utterly Broken. </em>To see the full list of available commands checkout the <a href="https://en.wikibooks.org/wiki/Linux_Guide/Freezes">wikibook guide on linux freezes</a>. </p><h3 id="the-last-last-resort-%F0%9F%A4%AE">The Last Last Resort &#x1F92E;</h3><div class="kg-card kg-callout-card kg-callout-card-red"><div class="kg-callout-emoji">&#x26A0;&#xFE0F;</div><div class="kg-callout-text">This can cause problems to your machine and the file system so be warned about the risks.</div></div><p>If everything else has failed, well it might be time to perform a hard reset, this means to press the physical power button on your machine in order to send the signal to the kernel to perform a reset. If this doesn&apos;t work you could try long pressing or cutting off electrical power to the machine.</p><hr><h3 id="resources">Resources</h3><p>This post is based on information retrieved by the following guides and blog posts, so if you want more information on this matter I recommend you check them out:</p><figure class="kg-card kg-bookmark-card"><a class="kg-bookmark-container" href="https://en.wikibooks.org/wiki/Linux_Guide/Freezes"><div class="kg-bookmark-content"><div class="kg-bookmark-title">Linux Guide/Freezes - Wikibooks, open books for an open world</div><div class="kg-bookmark-description"></div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="https://en.wikibooks.org/static/favicon/wikibooks.ico" alt="Linux unfreeze guide"><span class="kg-bookmark-author">Wikimedia Foundation, Inc.</span><span class="kg-bookmark-publisher">Contributors to Wikimedia projects</span></div></div><div class="kg-bookmark-thumbnail"><img src="https://en.wikibooks.org/static/images/footer/wikimedia-button.png" alt="Linux unfreeze guide"></div></a></figure><figure class="kg-card kg-bookmark-card"><a class="kg-bookmark-container" href="https://itsfoss.com/what-is-tty-in-linux/"><div class="kg-bookmark-content"><div class="kg-bookmark-title">What is TTY in Linux? - It&#x2019;s FOSS</div><div class="kg-bookmark-description">You must have heard about the term &#x201C;TTY&#x201D; when it comes to Linux and UNIX. But, what is it actually? This article explains the essentials.</div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="https://i0.wp.com/itsfoss.com/wp-content/uploads/2017/06/cropped-Logo-redsigned-without-name.png?fit=192%2C192&amp;ssl=1" alt="Linux unfreeze guide"><span class="kg-bookmark-author">It&apos;s FOSS</span><span class="kg-bookmark-publisher">Ankush Das</span></div></div><div class="kg-bookmark-thumbnail"><img src="https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/12/What-is-TTY-in-Linux.png?fit=800%2C450&amp;ssl=1" alt="Linux unfreeze guide"></div></a></figure><figure class="kg-card kg-bookmark-card"><a class="kg-bookmark-container" href="https://en.wikipedia.org/wiki/Teleprinter"><div class="kg-bookmark-content"><div class="kg-bookmark-title">Teleprinter - Wikipedia</div><div class="kg-bookmark-description"></div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="https://en.wikipedia.org/static/apple-touch/wikipedia.png" alt="Linux unfreeze guide"><span class="kg-bookmark-author">Wikimedia Foundation, Inc.</span><span class="kg-bookmark-publisher">Contributors to Wikimedia projects</span></div></div><div class="kg-bookmark-thumbnail"><img src="https://upload.wikimedia.org/wikipedia/commons/8/89/WACsOperateTeletype.jpg" alt="Linux unfreeze guide"></div></a></figure>]]></content:encoded></item></channel></rss>