-1

I'm a self taught programmer starting to browse info about the range of C languages and Object Oriented Principles for developing iPhone and Android apps. One thing I come across often is mentions of what this or that language does at compile time or run time. I know I'm going to end up in a deep rabbit hole of studying, but how much further do I have to go with learning about compile and runtime in order to guide my decisions when I finally start writing my first lines of code? Will it make writing code faster and easier if I take the time to study compilers and such?

Spilot
  • 1,495
  • 8
  • 29
  • 55
  • primarily opinion based! – OBX Dec 24 '15 at 02:37
  • "but how much further do I have to go with learning about compile and runtime in order to guide my decisions when I finally start writing my first lines of code? Will it make writing code faster and easier if I take the time to study compilers and such? " imo, in programming it's important to learn by doing, it can be hard to absorb material about languages like these without motivation from a concrete task, even if it is an exercise. you should definitely "study compilers", knowing even just at a high-level how the compiler works will make you a much, much better programmer – Chris Beck Dec 24 '15 at 02:49

1 Answers1

3

C and C++ are statically typed programming languages, which in general need a compiler to produce the final runnable program. To run a program, you first need to compile it (at least in most typical implementations, although in theory one can come up with a C++ interpreter), then run the produced executable. This process takes some time, however you shouldn't be too concerned about it, especially at a beginning level. The issue becomes more serious when you have code that's spread across multiple compilation units, with tens of thousands on lines of code. So for the programs you'll write the compile time will be negligible.

Compile time becomes a bit more serious whenever you use a lot of template code, which needs to be instantiated for various types (which takes time at compilation), but again, for relatively small programs, this is a non-issue.

There is another more advanced topic called "template meta-programming", in which you can make the compiler perform "stuff" for you at compile time. In other words, the compiler performs (useful) computations during the process of code compilation. However, even if this topic is a cool one, and there are many gurus around here, you won't need it at first, and you can start learning it after you master the basic C++ techniques.

Studying how compilers work and such is fun, but it won't make your code run "faster". Using appropriate algorithms is what makes your code faster. Micro-optimizations come only after.

Community
  • 1
  • 1
vsoftco
  • 55,410
  • 12
  • 139
  • 252
  • Ok great. I just want to make sure I take my time learning as much as possible before I dive in and get stuck then have to run back to stack overflow to get help with something I maybe should have already known. I'm not sure why my question got down voted. Opinions are exactly what I need. – Spilot Dec 24 '15 at 02:50
  • @Spilot Stackoverflow is for specific questions, see http://stackoverflow.com/help/how-to-ask. As you may well know, opinion based question can raise a whole lot of debate, and are discouraged. – vsoftco Dec 24 '15 at 02:51
  • Good answer. As the question mentions *"what this or that language does"*, also noteworthy that C++ lacks "reflection" / "introspection" (the ability to have the program freely examine its own code structure to generate further code or make processing decisions), and run-time source code evaluation/execution, which some other languages do have, and which *very occasionally* can make it much easier and/or more concise to code a solution to a program. Again, knowing when and how to use these reasonably is a fairly advanced topic - no reason not to get started with whatever language now. – Tony Delroy Dec 24 '15 at 02:53
  • @TonyD Thanks! Although type traits and [`void_t` SFINAE](https://www.youtube.com/watch?v=Am2is2QCvxY) go a long way, almost towards a (compile-time) "reflective-able" C++. – vsoftco Dec 24 '15 at 02:54
  • @vsoftco: we get used to their limitations and stop thinking about the things we can't do with them, but not being able to e.g. enumerate and process the members of a class is a very serious limitation for reusable support for serialisation, injection of comparison operators (there's a separate proposal for `= default` for that, but it's pretty inflexible), creation of proxies for access to concrete types via an abstract interface... many, many useful things. – Tony Delroy Dec 24 '15 at 02:58
  • @TonyD Agree, but we cannot have everything in life ;) – vsoftco Dec 24 '15 at 02:59
  • @vsoftco: agreed - I greatly prefer C++ on balance despite these limitations. Cheers. – Tony Delroy Dec 24 '15 at 02:59
  • @vsoftco - I think the OP's concern was about what operations are performed at compile time versus what operations are performed at run time, as opposed to how long it takes to compile a project. C / C++ does allow casting to reinterpret an object, but that doesn't change the object's actual type. – rcgldr Dec 24 '15 at 03:19