Why start learning programming with C

Summary: The author of the article explains why C is good at the stage of training and pumping the brains of a future programmer. And after a while, or even in parallel, you can learn a more modern language and do, for example, Enterprise or Web development.





Photo: Liam Briese on Unsplash There are



more and more programming languages. Now there are about 700 of them. However, mostly developers use 20 of them. Here, as in many other areas, there are ratings, trends and even fashion.



Let's just name a few popular languages. For Enterprise development, Java is actively used (soon Kotlin will also be fixed there), C #, for Web development - JavaScript, Go, Python and PHP, for mobile development - Swift, Java / Kotlin, well, I dare to call JavaScript (because maybe, because React Native). Game developers often use C # and C ++. All of them are in demand for several reasons:



  • simplified syntax (for the most part) and clear semantics - against the background of the C language;
  • full-featured set of standard APIs;
  • active community support;
  • a growing ecosystem of frameworks and libraries.


The C language is used in the development of software and hardware solutions. In C, you can also partially implement the functionality of software products that are demanding on performance. Although not every programmer wants and can work on such projects. But back to the learning stage.



Typically, future developers start coding at school, university, or career change courses. The latter option, by the way, is now gaining popularity.



Sooner or later, they ask themselves: which programming language is better to learn first? At school and university, this question can be answered for you: most often, learning there begins with the C / C ++ language (just like that, through the "/"). But on alternative training sites, it is unlikely that someone will also suggest you just study C to expand your horizons or pump your brains. Everyone wants to quickly, as they say, enter IT. So, as you can see, here and there you will have to show will and independence if you decide to start learning from the C language.  



In this article, we will talk about the stage of training and formation of a future specialist. Therefore, let me now state my arguments, and then you can state yours.



C forces you to deeply work out the solution to the problem



More modern languages ​​offer several built-in abstractions (or abstractions from standard libraries) at once for all common occasions. This primarily applies to standard algorithmic problems. For example, if you need to copy specific elements from the first array to the second, you can use the built-in filter () method in JavaScript. If you are writing in Java, you have the filter () method from the java.util.stream package at your disposal. 



JavaScript: Array.filter ()



const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];
//     6,     
const result = words.filter(word => word.length > 6);  
console.log(result);
//    : Array ["exuberant", "destruction", "present"]
      
      





Java: stream (). Filter ()



List<String> lines = Arrays.asList("spray", "limit", "elite");

//  List  Stream
List<String> result = lines.stream()              
//   elite  
       .filter(line -> !"elite".equals(line))     

//      List
       .collect(Collectors.toList());   

//   :  spray, limit
        result.forEach(System.out::println);   
      
      





In the C language, especially for educational purposes, you can offer the following implementation (in order not to complicate the example, I changed the strings to numbers and changed the "filtering" condition):



#include <stdio.h>
#define SIZE 5

void copy_aka_filter_arr(double trg[], double src[], int n);

int main(void){
    int i;
    double source[SIZE] = {1.1, 2.2, 3.3, 4.4, 5.5};
    double target[SIZE];
   
 printf("Source:  ");
    for (i = 0; i < SIZE; i++){
        printf("%5.1f ", source[i]);
    }
    putchar('\n');
    copy_arr(target, source, SIZE);   
    return 0;
}

void copy_aka_filter_arr(double trg[], double src[], int n){
//  i-      ,    3.3. 
//    i-    0.0 
    int i;
    for (i = 0; i < n; i++){
            if (trg[i]) > 3.3){     
                trg[i] = src[i];
            }
            else{
                trg[i] = 0.0;
            }
    }       
    printf("Target: ");
    for (i = 0; i < SIZE; i++){
        printf("%5.1f ", trg[i]);
    }
    putchar('\n');
}
      
      







Trying to implement such functions by hand, you will come across fundamental principles and nuances that will need to be deeply understood. In particular, self-implementation of algorithms for processing data structures in the C language is a great way to learn how to solve problems, and not look for ready-made solutions. 



No matter what cool and advanced language you write in, from time to time there appear complex problems that cannot be solved using standard libraries and built-in abstractions. In these cases, such a skill is simply necessary.



By the way, developers participating in competitive hackathons often train this skill, solving non-standard problems just in C.



C lets you touch on "low-level" programming



It is convenient to write in modern high-level languages ​​(Python, C #, Java or whatever you like). However, these languages ​​are very limited in how they interact with the hardware. In other words, you won't get the full hardware experience until you start programming in C. Modern programming languages ​​hide hardware-dependent implementation details and instead emulate some kind of abstraction. In most cases, it is created using a virtual machine.



Unfortunately, beginners have no idea at all about memory management, file handling and code optimization, because they have never seen even examples of "low-level" programming in C. From this point of view, modern programming languages ​​automate and hide too much. The C language forces you to do a lot with your hands and write highly optimized code.



As for me, this is a must try for every professional developer. Well, at least a backender.



C teaches freedom and responsibility



When a programming language offers a set of human-friendly abstractions, it becomes less flexible. Every built-in or library method acts like a hard-coded black box. In other words, modern programming languages ​​hide implementation details and tell the developer to simply refer to a set of interfaces. Manual control of the allocation of dynamic memory in modern programming languages ​​is impossible in most cases. Meanwhile, C gives you real freedom, allowing you to choose how you implement it at a lower level.



C compilers, when properly optimized, generate incredibly fast assembly code. True, in addition to setting the necessary optimization flags for compilation, you also need to write high-performance source code yourself. In C, we must carefully declare variables, allocate and clean up memory in time, access resources, and remember to free them. If C was your first language, you’ll get used to using memory and resources rationally, and you’ll get used to choosing optimal data structures. This habit will continue as you start writing in other languages.



C motivates you to write clean code



Unlike modern programming languages, you will have to write many times more code to implement the same tasks in C. This is due to the fact that in C much has to be implemented at a lower level, rather than using built-in wrappers and abstractions from standard libraries that hide implementation details. As the number of lines in the code increases, the complexity of the code also increases. To compensate for this effect and maintain order in the project, you need to try to write clean and understandable code.



Writing clean code is a skill that is especially in demand when working on large commercial projects. If you can learn to write clean C code, it will be easier for you to do it in another, simpler language.



Not convinced yet?



With the active development of C ++, the C language has ceased to be perceived by many as an independent language. It seems to have become a subset of the C ++ language. It is clear that in fact this is not the case. C ++ is a truly modern programming language with a full-featured set of standard libraries. In my opinion, C ++ shouldn't be the first language worth learning. True, there is one caveat: if you want to specialize in it in the future, then go ahead. In this case, these two languages ​​can be learned in parallel, but at some point they will "intersect" - and the transition from C to C ++ will be organic and almost instantaneous. 



Almost all modern programming languages ​​compete with each other, introducing new syntax, semantics and extending standard libraries and frameworks. As they say, everything is for people. This is captivating. But if future developers start learning these languages ​​from scratch, they will miss out on the valuable opportunities provided by C. At some point, they simply cannot take a new step in their development, not knowing how the code works at a lower level, not even knowing how their favorite frameworks and libraries are implemented inside.



So choose C as your first programming language. It will take longer to learn, but will help you become an expert in more modern languages ​​very quickly in the future.






Cloud servers from Macleod are great for developing in C and other programming languages.



Register using the link above or by clicking on the banner and get a 10% discount for the first month of renting a server of any configuration!






All Articles