<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ashish Bailkeri</title>
    <description>The latest articles on DEV Community by Ashish Bailkeri (@aboss123).</description>
    <link>https://dev.to/aboss123</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F720677%2F4d96b5bd-7555-4446-8466-b7d5cf70b057.png</url>
      <title>DEV Community: Ashish Bailkeri</title>
      <link>https://dev.to/aboss123</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aboss123"/>
    <language>en</language>
    <item>
      <title>Calculate Your Code Performance</title>
      <dc:creator>Ashish Bailkeri</dc:creator>
      <pubDate>Sat, 23 Oct 2021 15:40:36 +0000</pubDate>
      <link>https://dev.to/aboss123/calculate-your-code-performance-1hai</link>
      <guid>https://dev.to/aboss123/calculate-your-code-performance-1hai</guid>
      <description>&lt;p&gt;Benchmarking your code is a very important step to maintaining good code. It does not particularly matter whether the language is "fast" or "slow" as each language has its target platform where it needs to do well.&lt;/p&gt;

&lt;h2&gt;
  
  
  JavaScript Benchmarking Code
&lt;/h2&gt;

&lt;p&gt;In JavaScript there is a really simple way to measure the performance of your code and can be rally useful to test easily on the client side of your web browser. &lt;/p&gt;

&lt;p&gt;Let's look at an example:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;reallyExpensiveFunction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;10000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hi&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;time&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;reallyExpensiveFunction&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;timeEnd&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;reallyExpensiveFunction&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We can bench our functions by using the function &lt;code&gt;console.time&lt;/code&gt; to start and &lt;code&gt;console.timeEnd&lt;/code&gt; to end our bench.&lt;/p&gt;

&lt;h3&gt;
  
  
  Here is an output you might get
&lt;/h3&gt;

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

&lt;p&gt;You can try this example on &lt;a href="https://replit.com/@aboss123/JSBench#index.js" rel="noopener noreferrer"&gt;repl-it&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  C Benchmarking Code
&lt;/h2&gt;

&lt;p&gt;Believe it or not, the same code in C is very similar to the JavaScript example.&lt;/p&gt;

&lt;p&gt;Let's look at this example:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;

&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;time.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;really_expensive_function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;10000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hi&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kt"&gt;clock_t&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;clock&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="n"&gt;really_expensive_function&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="kt"&gt;clock_t&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;clock&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="n"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Took %f seconds&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(((&lt;/span&gt;&lt;span class="kt"&gt;float&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;CLOCKS_PER_SEC&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;code&gt;clock_t&lt;/code&gt; is a typedef for &lt;code&gt;long&lt;/code&gt; on my machine and is likely the same for yours. Despite that, you should still use &lt;code&gt;clock_t&lt;/code&gt; as it may be different on different machines. We get the system time before and after the really expensive function and are able to get the amount of time in seconds.&lt;/p&gt;

&lt;p&gt;You can try this example on &lt;a href="https://replit.com/@aboss123/CBenchmark#main.c" rel="noopener noreferrer"&gt;repl-it&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Here is an output you might get
&lt;/h3&gt;

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

&lt;h2&gt;
  
  
  Understanding the Reality
&lt;/h2&gt;

&lt;p&gt;The examples are great for testing out small pieces of code but are not feasible for large code bases where complex benchmarking is necessary. &lt;/p&gt;

&lt;h2&gt;
  
  
  Complex Benchmarking
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Profiling

&lt;ul&gt;
&lt;li&gt;What does a profiler &lt;em&gt;actually&lt;/em&gt; do? A program profile gives the developer the ability to be able to measure both space and time complexity of their functions in their program. This is particularly important if your program has a major bottleneck causing slowdowns, which is especially disastrous if it is a system where many requests are made. An example of such a tool is &lt;a href="https://github.com/google/orbit" rel="noopener noreferrer"&gt;orbit&lt;/a&gt; which can visualize the performance points in your program.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Benchmarking IO Operations

&lt;ul&gt;
&lt;li&gt;IO operations are ones that take in user input or read or write to system files, mainly requiring operations from the operating system kernel. These operations are usually the most expensive operations in your program. However, since time spent in system calls is not manageable by the programmer, it is best to reduce the amount of system calls that are made to improve performance.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Distributed Systems

&lt;ul&gt;
&lt;li&gt;These systems are complicated and so it is necessary to make sure that the performance of the system is in check. In general this is because each computer is not entirely the same, and so it becomes difficult in order to assess performance accurately. Different computers have different CPUs, network sockets, and configurations and these computers interact with routers and other network systems that communicate with each other that impact the way performance is calculated. It is best to determine the performance of such systems in a way that gives &lt;strong&gt;relative&lt;/strong&gt; benchmark, or a benchmark that is good enough for a team working on it to be able to assess the program.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;JavaScript&lt;/strong&gt;:&lt;br&gt;
For JavaScript, there are already some good tools for benchmarking, most notable being &lt;a href="https://github.com/bestiejs/benchmark.js/" rel="noopener noreferrer"&gt;Benchmark.js&lt;/a&gt; and &lt;a href="https://github.com/jeffbski/bench-rest" rel="noopener noreferrer"&gt;Bench-Rest&lt;/a&gt;. Using these tools will allow you to be able to properly test the performance of your code. It is generally given that you want to use software already tested for acceptable benchmarking as the demos shown today are often trivial and may not give all the results you want.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C++&lt;/strong&gt;:&lt;br&gt;
C++ has quite a number of benchmarking libraries some of the recent ones involving C++ 20's flexibility. The most notable being &lt;a href="https://github.com/google/benchmark" rel="noopener noreferrer"&gt;Google Bench&lt;/a&gt; and &lt;a href="https://github.com/boost-ext/ut" rel="noopener noreferrer"&gt;UT&lt;/a&gt;. C does not have many specific benchmarking libraries, but you can easily integrate C code with C++ benchmarking libraries in order to test the performance of your C code.&lt;/p&gt;

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

&lt;p&gt;In the end it's up to you how you choose to benchmark your code. Generally, you want to code your project before you benchmark it and if performance is really a concern then you can opt to use these benchmarking libraries or use a performance profile to find bottlenecks. I hope you learned something today :).&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>cpp</category>
      <category>programming</category>
    </item>
    <item>
      <title>C++ Programming: Operator Overloading</title>
      <dc:creator>Ashish Bailkeri</dc:creator>
      <pubDate>Sat, 23 Oct 2021 15:32:39 +0000</pubDate>
      <link>https://dev.to/aboss123/c-programming-operator-overloading-2858</link>
      <guid>https://dev.to/aboss123/c-programming-operator-overloading-2858</guid>
      <description>&lt;p&gt;Operator overloading is one of the special features in C++ programming. The advantages of this feature is that it allows us to apply operators that logically make sense on our custom data structures. Let's how they can be used in real world applications.&lt;/p&gt;

&lt;p&gt;Looking at the first use of operator overloading, we can see it in &lt;code&gt;std::cout&lt;/code&gt; using the operator &lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt; that is overloaded to print values to our terminal. It is used as the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s"&gt;"Hello, World!&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="c1"&gt;//        ^^ &amp;lt;-- This is the overloaded operator&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is trivial, right? Most of us use it without giving it much thought, but it is important enough that overloading this operator for your own class allows &lt;code&gt;std::cout&lt;/code&gt; to print user-defined classes.&lt;/p&gt;

&lt;h2&gt;
  
  
  A real world example
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CustomVector&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;public:&lt;/span&gt;
  &lt;span class="k"&gt;explicit&lt;/span&gt; &lt;span class="n"&gt;CustomVector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;

  &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="k"&gt;operator&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;CustomVector&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;vec&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;vec&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;vec&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="n"&gt;CustomVector&lt;/span&gt; &lt;span class="k"&gt;operator&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;CustomVector&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;vec&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;CustomVector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;vec&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;vec&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So let's breakdown what is actually going on here. We have a class called &lt;code&gt;CustomVector&lt;/code&gt; and we give it the values of &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt;, now what do we do with this? We don't want to continuously compare the their x values all the time, so what we do instead is create on operator overload for the &lt;code&gt;==&lt;/code&gt; operator to do this for us.&lt;/p&gt;

&lt;p&gt;Writing operator functions is as simple as writing a normal function with the difference in the function name being &lt;code&gt;operator&lt;/code&gt; followed by a valid operator to overload. In fact, C++ will allow you to overload the &lt;code&gt;new&lt;/code&gt; and &lt;code&gt;delete&lt;/code&gt; keywords too, although this is not generally recommended. &lt;/p&gt;

&lt;h3&gt;
  
  
  Applying operators and using &lt;code&gt;std::cout&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;After our implementation of the &lt;code&gt;+&lt;/code&gt; operator, we can add this line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="k"&gt;friend&lt;/span&gt; &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;ostream&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="k"&gt;operator&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;ostream&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;CustomVector&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;vec&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you don't know what friend functions or classes are, they allow functions and classes to access private variables of a given class.&lt;/p&gt;

&lt;p&gt;Finally, we can add our implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;ostream&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="k"&gt;operator&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;ostream&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;CustomVector&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;vec&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s"&gt;"{ x: "&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;vec&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s"&gt;", "&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s"&gt;"y: "&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;vec&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s"&gt;" }"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Brief overview of the parameters shows that we take in an instant of the output stream and an instance of our custom class. Not so bad, right?&lt;/p&gt;

&lt;h3&gt;
  
  
  Checking our results
&lt;/h3&gt;

&lt;p&gt;Now let's test our code to see it work in action:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;CustomVector&lt;/span&gt; &lt;span class="n"&gt;vec&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;CustomVector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;1.0&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;1.0&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="n"&gt;CustomVector&lt;/span&gt; &lt;span class="n"&gt;vec2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;CustomVector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;2.0&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;2.0&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vec&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;vec2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s"&gt;"They are equal&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s"&gt;"They are not equal&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s"&gt;"Vec 1: "&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;vec&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s"&gt;"Vec 2: "&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;vec2&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s"&gt;"Vec 3: "&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;vec&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;vec2&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is what you should see when you run your code:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F79mzcpy5dgt9fw196vh4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F79mzcpy5dgt9fw196vh4.png" alt="Result"&gt;&lt;/a&gt;&lt;br&gt;
You can play around with this to get a better fell of it &lt;a href="https://replit.com/@aboss123/OperatorOverloading#main.cpp" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

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

&lt;p&gt;Operator overloading can be confusing at times so it is best to take it slow when using this concept. Be sure to use this appropriately as to not write confusing code, and make sure that you allow flexibility in the classes you write. As with many things in C++, it is easy to shoot yourself in the foot when programming, so be careful. I hope you learned something today from this overview :)&lt;/p&gt;

</description>
      <category>cpp</category>
      <category>beginners</category>
      <category>programming</category>
      <category>productivity</category>
    </item>
    <item>
      <title>C++ Programming:  Implicit and Explicit Constructors</title>
      <dc:creator>Ashish Bailkeri</dc:creator>
      <pubDate>Mon, 18 Oct 2021 15:48:34 +0000</pubDate>
      <link>https://dev.to/aboss123/c-programming-implicit-and-explicit-constructors-27be</link>
      <guid>https://dev.to/aboss123/c-programming-implicit-and-explicit-constructors-27be</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Any code snippets posted here are licensed under the &lt;strong&gt;MIT License&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Did you know that there are both implicit and explicit constructors? &lt;br&gt;
Let's look into the difference between both, and what each can do for code readability and convivence when programming.&lt;/p&gt;
&lt;h2&gt;
  
  
  Explicit Constructors
&lt;/h2&gt;

&lt;p&gt;You may see warnings in certain C++ compilers about making certain constructors explicit. But what does it mean? Let's look at an example of an explicit constructor:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyClass&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;explicit&lt;/span&gt; &lt;span class="n"&gt;MyClass&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// ...&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;MyClass&lt;/span&gt; &lt;span class="n"&gt;clz&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;MyClass&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Looks pretty normal, right? So you might wonder what this actually does. You must initialize the value with the name of the type before it's initialization aka: &lt;code&gt;MyClass&lt;/code&gt; then with the constructor parameters. You can see the difference in usability in the implicit constructor code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Implicit Constructors
&lt;/h2&gt;

&lt;p&gt;These constructors allow you to initialize a class value without specifying the name of the class. Let's look at an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyClass&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="cm"&gt;/*implicit*/&lt;/span&gt; &lt;span class="n"&gt;MyClass&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// ...&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;MyClass&lt;/span&gt; &lt;span class="n"&gt;clz&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wait, is the class &lt;code&gt;MyClass&lt;/code&gt; now the integer type? &lt;strong&gt;No.&lt;/strong&gt; What actually happened was that the C++ compiler was able to tell that you were calling the &lt;code&gt;MyClass&lt;/code&gt; constructor implicitly and allowed that conversion. &lt;/p&gt;

&lt;p&gt;Every wondered why this code was legal?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;my_string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Wow, this is cool!"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's because there is an implicit constructor with std::string that takes in a &lt;code&gt;const char *&lt;/code&gt; and thus allows this initialization to be valid.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bringing It Together
&lt;/h2&gt;

&lt;p&gt;In accordance with certain code writing standards, compilers or code analyzers may warn using implicit constructors, why? They do this because in general it is harder for another programmer to analyze code that uses implicit constructors because it is hard to pin point the type of the object being initialized.&lt;/p&gt;

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

&lt;p&gt;Understanding implicit and explicit constructors will allow you to take in full control of how your code is read and how you use it. This is especially important to take note of if you are reviewing code, or reading code from a library. I hope you learned something today, and have good day!&lt;/p&gt;

</description>
      <category>cpp</category>
      <category>beginners</category>
      <category>programming</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Why Good Syntax Highlighting is Important</title>
      <dc:creator>Ashish Bailkeri</dc:creator>
      <pubDate>Sun, 17 Oct 2021 18:30:11 +0000</pubDate>
      <link>https://dev.to/aboss123/why-good-syntax-highlighting-is-important-4gan</link>
      <guid>https://dev.to/aboss123/why-good-syntax-highlighting-is-important-4gan</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;All code snippets posted are under the &lt;strong&gt;MIT License&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  So does it really matter?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Yes.&lt;/strong&gt; There good programming practices in certain programming languages but there is also good developing practices and this is one of them. &lt;/p&gt;

&lt;h2&gt;
  
  
  So what are the advantages?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Higher Productivity 

&lt;ul&gt;
&lt;li&gt;When programming with better syntax highlighting it becomes easier to identify where parts of your program is based on the color. With color schemes with limiting syntax highlighting on certain semantics, it can be really difficult to differentiate between what may be a parameter variable or a local variable, or in the case of C++, macros, enum values, global variables, etc.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Encourages you to code

&lt;ul&gt;
&lt;li&gt;What do I mean by this? I mean that you actually feel more engaged looking at a theme bested suited to your programming style, for me, I prefer a diverse array of colors on my screen.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Let me show you what I mean:&lt;/p&gt;

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

&lt;blockquote&gt;
&lt;p&gt;Snippet from &lt;a href="https://github.com/The-NextGen-Project/jet" rel="noopener noreferrer"&gt;&lt;strong&gt;Jet&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;What does this do well? It has a vast amount of colors that is easy to differentiate parts of the program immediately, it is not just about I have highlighting, but it really tries and brings out different parts of the program. I can easily point out macros, class variables, parameters, and functions almost instantly through this highlighting. &lt;br&gt;
But for some, this might be overkill in colors, and you may prefer a softer tone.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; This is my opinion of course, but in general you should choose a theme that suits your programming style the best&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Of course, this also depends on your editor's capability but other popular editors like Visual Studio Code, still provide support for &lt;a href="https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide" rel="noopener noreferrer"&gt;semantic highlighting&lt;/a&gt;. But we can see clearly how this highlighting can improve the coder's experience and provides clarity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Another Interesting Example&lt;/strong&gt;:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnul4bkga0fbhh4zkpm76.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnul4bkga0fbhh4zkpm76.png" alt="Okay Syntax Highlighting Example"&gt;&lt;/a&gt;&lt;br&gt;
This theme is known as &lt;strong&gt;Darcula&lt;/strong&gt;, JetBrains's default dark theme syntax highlighting, and while it does the job, is less colorful. Important type values such as &lt;code&gt;size_t&lt;/code&gt; don't have clear highlighting in this example and can easily be overlooked as they have a very similar color to the delimiter tokens. This is not say it isn't a good theme, it is, and is far better than editors with only keyword highlights. What does it do well? It has a far softer theme than the previous example, and still manages to highlight important parts of the program. &lt;/p&gt;

&lt;p&gt;In general, good syntax highlighting themes needs to be able to have ways of identifying important parts of the program, and JetBrains's IDE's usually give the programmer enough flexibility to adjust their highlighting.&lt;/p&gt;

&lt;h2&gt;
  
  
  Disadvantages of Good Syntax Highlighting
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Get lost in the sea of colors that is your code

&lt;ul&gt;
&lt;li&gt;No? That's just me? Well let's move on then.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

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

&lt;p&gt;My opinion is this: the making of a good programmer is one that knows how to use the tools available today to further increase their skills, and this includes something as subtle as syntax highlighting and font choice. You don't have to stick with something like my syntax highlighting, rather you should find the one best suitable for you.&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>beginners</category>
      <category>development</category>
      <category>programming</category>
    </item>
    <item>
      <title>C++ Programming: Arena Allocation</title>
      <dc:creator>Ashish Bailkeri</dc:creator>
      <pubDate>Sat, 16 Oct 2021 22:33:56 +0000</pubDate>
      <link>https://dev.to/aboss123/advanced-c-arena-allocation-3580</link>
      <guid>https://dev.to/aboss123/advanced-c-arena-allocation-3580</guid>
      <description>&lt;p&gt;Hi Everyone, I'm going to starting a mini series of articles about  C++ Programming concepts that you may be using in your projects. Today's topic is: &lt;strong&gt;Arena Allocation&lt;/strong&gt;. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Code snippets and images posted in this article are under the &lt;strong&gt;MIT License&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Edit: Some ambiguous information has been cleared up&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Memory management is a pain, isn't it?
&lt;/h2&gt;

&lt;p&gt;When working in garbage collected languages such as Java or Go, you may be mostly free from dealing closely with memory but in languages like C and C++, memory usually causes a lot of problems, especially since you have a lot of power to manipulate it.&lt;/p&gt;

&lt;h2&gt;
  
  
  So what's the best allocator?
&lt;/h2&gt;

&lt;p&gt;There is no number 1 best allocator in every scenario, rather, if you wanted the best allocator, the programmer is the best allocator because they know exactly what the program will do and thus know the best way to allocate memory.&lt;/p&gt;

&lt;h2&gt;
  
  
  Arena Allocation
&lt;/h2&gt;

&lt;p&gt;Instead of allocating pointers using &lt;code&gt;malloc&lt;/code&gt; or &lt;code&gt;new&lt;/code&gt;, we can create our own allocator known as the arena allocator.&lt;/p&gt;

&lt;p&gt;This kind of allocation involves allocating a large chunk of memory before the logic of your program executes, for example, 20 GiB of memory. Wait, hold up, this sound completely unreasonable right? Yes, it is, but the operating system knows this too, so it allows &lt;a href="https://en.wikipedia.org/wiki/Memory_overcommitment" rel="noopener noreferrer"&gt;overcommitting memory&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Linux Overcommit
&lt;/h3&gt;

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

&lt;h3&gt;
  
  
  Mac Overcommit
&lt;/h3&gt;

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

&lt;h3&gt;
  
  
  Windows Overcommit
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt;: Windows doesn't have the same ability to overcommit memory, rather large amounts of memory can be reserved and then requested&lt;/p&gt;
&lt;/blockquote&gt;

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

&lt;h4&gt;
  
  
  When you have your large amount memory allocated, what do you do with it?
&lt;/h4&gt;

&lt;p&gt;Generally the block of memory can be separated into chunks, known as a memory pool, and parts of the program may be assigned dedicated amounts of memory. This is the approach of a &lt;a href="https://en.wikipedia.org/wiki/Memory_pool" rel="noopener noreferrer"&gt;&lt;strong&gt;pool allocator&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For simplicity sake, a arena allocator is usually implemented with allocations done linearly.&lt;/p&gt;

&lt;h4&gt;
  
  
  Why would you use arena allocation?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Faster allocation

&lt;ul&gt;
&lt;li&gt;A large block of memory is allocated as a huge chunk meaning that allocation is as simple as incrementing the amount of bytes that have been written&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Cache efficiency 

&lt;ul&gt;
&lt;li&gt;With a large chunk of memory being allocated it is likely that values will be allocated in continuous memory&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Almost no cost freeing

&lt;ul&gt;
&lt;li&gt;In general, with a large chunk of memory that is allocated, you can free the memory all at once with almost no cost.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Arena allocation may not be the right for your use case. In most cases, if you do not see the user or your program using past a certain amount of memory, it is preferable to use alternative methods of allocation, and usually general purpose allocators are good enough.&lt;/li&gt;
&lt;li&gt;Large amounts of memory allocated at the beginning of a program &lt;em&gt;may&lt;/em&gt; go to waste if you choose this allocator to just get rid of memory handling issues. Arena allocation has its own specific use cases or areas where it is reasonable to use it like in Compiler Construction.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Create an allocator
&lt;/h3&gt;

&lt;p&gt;Here is an extremely basic arena allocation setup:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4gu1qrz4qvmv0vood1r1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4gu1qrz4qvmv0vood1r1.png" alt="Allocator Data Structure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The way this is setup is pretty generic, it allows me to create multiple allocators for different parts of my program.&lt;/p&gt;

&lt;p&gt;If you wanted to distribute your memory instead of allocating it linearly, you could do as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Part A of Program &lt;em&gt;5 GiB&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Part B of Program &lt;em&gt;10 GiB&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Part C of Program &lt;em&gt;5 GiB&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is how the large pool of memory can be distributed and is useful if you know which part allocates more memory.&lt;/p&gt;

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

&lt;p&gt;Arena allocation is just another tool in the box that will help you advance your knowledge of low-level programming in C++. Be sure to understand how your specific program works before choosing this allocation method. Understanding allocators behind the scenes will help you in general for any kind of endeavor and I hope you learned something from this.&lt;/p&gt;

</description>
      <category>cpp</category>
      <category>algorithms</category>
      <category>programming</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Jet: Programming Language that puts developers first.</title>
      <dc:creator>Ashish Bailkeri</dc:creator>
      <pubDate>Wed, 06 Oct 2021 21:28:05 +0000</pubDate>
      <link>https://dev.to/aboss123/jet-programming-language-simple-but-powerful-language-for-native-and-web-applications-21eo</link>
      <guid>https://dev.to/aboss123/jet-programming-language-simple-but-powerful-language-for-native-and-web-applications-21eo</guid>
      <description>&lt;p&gt;Hi Everyone!&lt;/p&gt;

&lt;p&gt;I'm Ashish and this is my first post on the platform and I'm very excited to share my project &lt;a href="https://github.com/The-NextGen-Project/jet" rel="noopener noreferrer"&gt;Jet&lt;/a&gt;. This post is for updates and recent developments for the programming language I am developing.&lt;/p&gt;

&lt;h2&gt;
  
  
  About
&lt;/h2&gt;

&lt;p&gt;If you have ever tried to develop an application, you know hard it is to get your app up and running on your desired platform, but even more exhausting to develop one for multiple platforms, especially when scrolling through piles of error messages. This is where Jet comes in to help. Jet seeks to provide the highest performance applications in both the Web and in Native environments while keeping the developer informed of what &lt;strong&gt;actually&lt;/strong&gt; caused the error.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding The Language
&lt;/h2&gt;

&lt;p&gt;There is no need to discuss the entire language specifics here, but you can totally read about it on our &lt;a href="https://github.com/The-NextGen-Project/jet/blob/main/LANG.md" rel="noopener noreferrer"&gt;Github&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's new, and what's planned?
&lt;/h2&gt;

&lt;p&gt;The language has had a variety of features planned and fine-tuned to create simple and flexible language.&lt;/p&gt;

&lt;h3&gt;
  
  
  Error Messages
&lt;/h3&gt;

&lt;p&gt;One of Jet's main strengths are its error messages. When I first learned programming, they had a whole lesson teaching on how to interpret stack traces and error messages, this should not be how it works!&lt;/p&gt;

&lt;p&gt;Error messages should be clear and explain to the programmer what they did wrong. Let's look at an example:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fycq9lh0jcc4jaukll2z4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fycq9lh0jcc4jaukll2z4.png" alt="ParseErrorExample2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here we get a clear reason as to the error, and we get the location to fix the problem. And yes, this is output on a &lt;strong&gt;Windows&lt;/strong&gt; machine, your eyes do not deceive you. This is the output we get on all platforms &lt;strong&gt;Mac, Linux, and Windows&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If we look at the same error in C++, however, we get a nasty error message:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl6e1mb4kfw8lovv9no3r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl6e1mb4kfw8lovv9no3r.png" alt="BadC++Error"&gt;&lt;/a&gt;&lt;br&gt;
Along with some compiler gibberish, it doesn't even tell us where to fix the problem! This is not how programming languages should be designed. This is especially tricky if you are missing braces in a sequence of braces.&lt;/p&gt;

&lt;p&gt;Let's have a look at another example:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx6ukdcohlaearn1r8pth.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx6ukdcohlaearn1r8pth.png" alt="LexErrorExample2"&gt;&lt;/a&gt;&lt;br&gt;
Here we get a list of possible values that are acceptable and tell the programmer why the compiler errored out. In C++, we don't even get an error, worse, its designated as a warning which commonly overlooked and can lead to undefined behavior. &lt;/p&gt;

&lt;p&gt;We take inspiration in our error messages from Rust and Elm to increase the productivity of the developer.&lt;/p&gt;
&lt;h3&gt;
  
  
  Updates
&lt;/h3&gt;

&lt;p&gt;Jet has removed some extra features that do not sit well for the core language and has now made explicit grammar definitions for enums and a structures.&lt;/p&gt;
&lt;h4&gt;
  
  
  Compile-time code execution
&lt;/h4&gt;

&lt;p&gt;Inspired by the &lt;em&gt;Jai Programming Language&lt;/em&gt; by Johnathon Blow, we have based a lot of different principles in the language after that, including compile-time code execution.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="n"&gt;does_something&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"Hi"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="n"&gt;another_function&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Variable `some_value` evaluated at compile-time&lt;/span&gt;
  &lt;span class="n"&gt;some_value&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;does_something&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Code Generation
&lt;/h4&gt;

&lt;p&gt;Jet's current state is in the midst of type-checking and &lt;em&gt;C Programming Language&lt;/em&gt; code generation. However, we don't intend to solely rely on C, there is &lt;a href="https://github.com/The-NextGen-Project/jet/blob/dev/lib/jet-x64-assembler.cpp" rel="noopener noreferrer"&gt;x64 Backend&lt;/a&gt; in its testing phase too. &lt;/p&gt;

&lt;p&gt;JavaScript code generation is also on high priority after the C backend, as we want Jet code to get up and running on the web as soon as possible. In order to keep up with those who dislike manual memory management, &lt;strong&gt;smart pointers&lt;/strong&gt; are already planned to be implemented in the near future which will translate well into JavaScript code generation. &lt;/p&gt;

&lt;h4&gt;
  
  
  Web Development
&lt;/h4&gt;

&lt;p&gt;In order to live up to expectations, web development is in the works, too. A complete web project consists not just of JavaScript files and other programming language build files may be necessary, so Jet is keen on generating complete projects that interact with every aspect to launching existing code on the web.&lt;/p&gt;

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

&lt;p&gt;Jet is planned to have close to 90% of features to be implemented and tested with code generation within the next year, and hopefully begins its user-base testing in the Spring of 2022.&lt;/p&gt;

&lt;p&gt;I would love any feedback that is to be given on the language, and contributions are always made welcome, and are really helpful too!&lt;br&gt;
Make sure to star the &lt;a href="https://github.com/The-NextGen-Project/jet/tree/dev" rel="noopener noreferrer"&gt;repo&lt;/a&gt; and watch it for updates as they present themselves on Github, and I hope to give you another update in the future.&lt;/p&gt;

&lt;p&gt;Thank you for your time!&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>javascript</category>
      <category>c</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
