{"id":29,"date":"2017-04-12T23:53:07","date_gmt":"2017-04-12T20:23:07","guid":{"rendered":"http:\/\/haghiri75.com\/en\/?p=29"},"modified":"2017-04-12T23:53:07","modified_gmt":"2017-04-12T20:23:07","slug":"how-to-make-a-computer-program","status":"publish","type":"post","link":"https:\/\/haghiri75.com\/en\/how-to-make-a-computer-program\/","title":{"rendered":"How to make a computer program"},"content":{"rendered":"<p>This is a clich\u00e9 in IT and computer related blogs. You can find at least one topic on <em><strong>How to make a computer program <\/strong><\/em>in every blog written by a computer expert (scientist, engineer or experimental expert). So, I also decided to write about it. In this topic, I&#8217;m going to explain how your idea can be a program.<\/p>\n<p>I&#8217;m not a startup or business person, and I hate when someone wants to teach other people <em>how to have an idea <\/em>so I consider you already have an idea, and you want to implement your idea as a computer program. Let&#8217;s start!<\/p>\n<h2>Choose your target hardware<\/h2>\n<p>Unfortunately, a lot of programmers ignore this important step, but if you consider a special hardware to develop and implement your ideas, you will have two points :<\/p>\n<ol>\n<li>You learn a new hardware architecture (and maybe organization)<\/li>\n<li>You help someone who wants a specific application on that hardware.<\/li>\n<\/ol>\n<p>Sometimes, you realize that writing a calculator is pretty stupid. Of course it is when you write a calculator for Windows or macOS. But, when you write a calculator for Arduino, which can interact with a keypad and displays, it&#8217;s not.<\/p>\n<h2>Write Algorithm<\/h2>\n<p>Actually, algorithm is <strong>explaining the way we solve the problems.<\/strong> So, we need to write the steps of our solution and test it. Sometimes, when we write a simple algorithm, it&#8217;s not efficient at all, and needs a lot of improvements. Imagine this (This algorithm makes all even numbers lesser than 100:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\">while( a &lt; 100){\r\n if(a%2 == 0){\r\n  puts(a);\r\n }\r\n a++;\r\n}<\/pre>\n<p>This is a piece of larger code. But wait,\u00a0 how can we improve that? That <em>if <\/em>there can make this piece of code slower. But, if we consider a = 0, we can write something like this :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\">for(int a = 0; a &lt; 100; a + 2){\r\n puts(a);\r\n}<\/pre>\n<p>You know, I wrote a shorter code here. Also, this short code has a better structure of making all even numbers lesser than 100.\u00a0 But I think both of these codes have the same time complexity, so there is no difference. If we had two nested loops, and the inner loop&#8217;s condition had effects on the outer loop&#8217;s condition, we had to spend time on calculating time complexity and optimizing it.<\/p>\n<p>Finally, you will realize there are some &#8220;classic&#8221; algorithms, which are already optimized, and you can just use them, and model your idea with them.<\/p>\n<h2>Choose the language<\/h2>\n<p>This step is also one of the most important ones. Imagine if you want to program an AVR chip, of course JavaScript is not the best choice. There are tools which allow you to write programs for those chips in JS, but the language is not made for communication with AVR! But, when you want to program a website, specially when you&#8217;re dealing with front-end stuff, C is not your best choice! But wait, if the program we want to make is a general purpose desktop program or a school\/university project, we are actually free to choose the language!<\/p>\n<p>Imagine we want to write a simple program, which does Addition with <em>bitwise operations.<\/em> We can write our program in C\/C++ like this :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\">#include &lt;stdio.h&gt;\r\n\r\nint bitwiseAdd(int x, int y){\r\n while(y != 0) {\r\n  int carry = x &amp; y;\r\n  x = x ^ y;\r\n  y = carry &lt;&lt; 1; \r\n }\r\n return x;\r\n}\r\n\r\nint main(){\r\n printf(\"%d\\n\", bitwiseAdd(10 , 5));\r\n return 0;\r\n}<\/pre>\n<p>And you can write it in Ruby like this :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"ruby\">def bitwiseAdd(x, y)\r\n while y != 0\r\n  carry = x &amp; y\r\n  x = x ^ y\r\n  y = carry &lt;&lt; 1\r\n end\r\n return x\r\nend\r\n\r\nputs bitwiseAdd(10, 15)<\/pre>\n<p>But, when you want to directly communicate with hardware, you&#8217;ll need a low-level language. C\/C++ are actually mid-level languages. They can help you communicate with hardware (like this piece of AVR code) :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\">while(1){\r\n PORTC.1 = 0;\r\n delay_ms(1000);\r\n PORTC.1 = 1;\r\n delay_ms(1000);\r\n}<\/pre>\n<p>or like that bitwiseAdd(x, y) function , they can help us write normal programs. But Assembly language is a really low-level language. We can use it when we need to talk to our hardware directly.<\/p>\n<p>You see, all programming languages can help us, but depending on the conditions, we can use different languages.<\/p>\n<h2>And &#8230;?<\/h2>\n<p>And now, you probably know how a computer program is made. But, if you really want to become a developer, you have to study about paradigms, methodologies, etc. I tried to keep it simple in this article, but later, I&#8217;ll write about those topics more.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a clich\u00e9 in IT and computer related blogs. You can find at least one topic on How to make a computer program in every blog written by a computer expert (scientist, engineer or experimental expert). So, I also decided to write about it. In this topic, I&#8217;m going to explain how your idea &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/haghiri75.com\/en\/how-to-make-a-computer-program\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to make a computer program&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_newsletter_tier_id":0,"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[2],"tags":[23,11,13,22,12,15,24,25],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8BkKn-t","jetpack-related-posts":[{"id":97,"url":"https:\/\/haghiri75.com\/en\/how-to-be-a-hardware-engineer\/","url_meta":{"origin":29,"position":0},"title":"How to be a hardware engineer","author":"prp-e","date":"October 4, 2017","format":false,"excerpt":"A computer, is made up of hardware and software. Lots of people like to write and develop software, so the internet is full of topics like \"How to be a software engineer\" or \"how to write a computer program\" and also, there is a lot of great and free tutorials\u2026","rel":"","context":"In &quot;Computer Architecture &amp; Programming&quot;","block_context":{"text":"Computer Architecture &amp; Programming","link":"https:\/\/haghiri75.com\/en\/category\/computer\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":16,"url":"https:\/\/haghiri75.com\/en\/microcontrollers-design-and-implementation-released\/","url_meta":{"origin":29,"position":1},"title":"Microcontrollers, Design and Implementation released!","author":"prp-e","date":"April 4, 2017","format":false,"excerpt":"It was about two years I started serious study on computer architecture. In these years, I learned a lot and I could simulate and implement a microprocessor, similar to real ones. In Summer 2016, I decided to share my experience with others. Then, I started writing this book. This book\u2026","rel":"","context":"In &quot;Computer Architecture &amp; Programming&quot;","block_context":{"text":"Computer Architecture &amp; Programming","link":"https:\/\/haghiri75.com\/en\/category\/computer\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":86,"url":"https:\/\/haghiri75.com\/en\/importance-of-iot\/","url_meta":{"origin":29,"position":2},"title":"Importance of IoT","author":"prp-e","date":"August 23, 2017","format":false,"excerpt":"For the last 25 years, a ghost is flying over our world, it's the ghost of \"Internet\". From 80's, internet became one of the most used tools for international communications, such as knowledge sharing. So, a lot of people started using internet to share knowledge, to do research or even\u2026","rel":"","context":"In &quot;Computer Architecture &amp; Programming&quot;","block_context":{"text":"Computer Architecture &amp; Programming","link":"https:\/\/haghiri75.com\/en\/category\/computer\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":44,"url":"https:\/\/haghiri75.com\/en\/reverse-engineering-of-8086-from-a-calculator-to-the-most-used-processor\/","url_meta":{"origin":29,"position":3},"title":"Reverse engineering of 8086, from a calculator to the most used processor","author":"prp-e","date":"April 22, 2017","format":false,"excerpt":"If you have a laptop or desktop computer, you probably use a 8086-based CPU, or one implementation of x86 family to be exact. For example, I have a Lenovo laptop with a Core i5 CPU, which is based on x86 architecture. In this article, I want to talk about x86\u2026","rel":"","context":"In &quot;Computer Architecture &amp; Programming&quot;","block_context":{"text":"Computer Architecture &amp; Programming","link":"https:\/\/haghiri75.com\/en\/category\/computer\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":202,"url":"https:\/\/haghiri75.com\/en\/severus-does-the-magic\/","url_meta":{"origin":29,"position":4},"title":"Severus does the magic","author":"prp-e","date":"September 11, 2022","format":false,"excerpt":"It is not too long after I told you that I was too cheap to pay $10 a month for github copilot and I came up with the idea for Severus, my own AI pair programmer. It was something that went boom. My blog usually doesn't have more than 20\u2026","rel":"","context":"In &quot;Computer Architecture &amp; Programming&quot;","block_context":{"text":"Computer Architecture &amp; Programming","link":"https:\/\/haghiri75.com\/en\/category\/computer\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/haghiri75.com\/en\/wp-content\/uploads\/warforged_wizard_by_captdiablo_de2mwm8-pre-1024x724.jpg?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/haghiri75.com\/en\/wp-content\/uploads\/warforged_wizard_by_captdiablo_de2mwm8-pre-1024x724.jpg?resize=350%2C200 1x, https:\/\/i0.wp.com\/haghiri75.com\/en\/wp-content\/uploads\/warforged_wizard_by_captdiablo_de2mwm8-pre-1024x724.jpg?resize=525%2C300 1.5x"},"classes":[]},{"id":161,"url":"https:\/\/haghiri75.com\/en\/analyzing-components-of-an-electric-circuit-with-yolov5\/","url_meta":{"origin":29,"position":5},"title":"Analyzing components of an electric circuit with YOLOv5","author":"prp-e","date":"January 14, 2022","format":false,"excerpt":"In past recent weeks, I did a lot with YOLOv5. A few weeks prior to this article, I wrote an article on why I love YOLOv5 and later, I did a project with YOLOv5 which was somehow a try for making something like symbolab or similar software. I explained that\u2026","rel":"","context":"In &quot;Computer Architecture &amp; Programming&quot;","block_context":{"text":"Computer Architecture &amp; Programming","link":"https:\/\/haghiri75.com\/en\/category\/computer\/"},"img":{"alt_text":"Electric Circuit component analysis using YOLOv5","src":"https:\/\/i0.wp.com\/haghiri75.com\/en\/wp-content\/uploads\/Screen-Shot-2022-01-13-at-1.05.41-AM-1024x583.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/haghiri75.com\/en\/wp-content\/uploads\/Screen-Shot-2022-01-13-at-1.05.41-AM-1024x583.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/haghiri75.com\/en\/wp-content\/uploads\/Screen-Shot-2022-01-13-at-1.05.41-AM-1024x583.png?resize=525%2C300 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/haghiri75.com\/en\/wp-json\/wp\/v2\/posts\/29"}],"collection":[{"href":"https:\/\/haghiri75.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/haghiri75.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/haghiri75.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/haghiri75.com\/en\/wp-json\/wp\/v2\/comments?post=29"}],"version-history":[{"count":13,"href":"https:\/\/haghiri75.com\/en\/wp-json\/wp\/v2\/posts\/29\/revisions"}],"predecessor-version":[{"id":42,"href":"https:\/\/haghiri75.com\/en\/wp-json\/wp\/v2\/posts\/29\/revisions\/42"}],"wp:attachment":[{"href":"https:\/\/haghiri75.com\/en\/wp-json\/wp\/v2\/media?parent=29"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/haghiri75.com\/en\/wp-json\/wp\/v2\/categories?post=29"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/haghiri75.com\/en\/wp-json\/wp\/v2\/tags?post=29"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}