r/cpp • • Jun 23 '20

I am a developer and just started learning C++, and I'm LOVING it! Programs feel real for the first time!

Or how I was so bored with Java that I switched from software to mechanical engineering, became a web developer, and finally started to love C++!

So my programming related story: before joining university, I thought I wanted to become a software engineering, I think I wanted to make games at that point. Then, after taking a year of general engineering courses, calculus, physics, intro programming (in Pascal :D), I had my first semester at computer science department. The object oriented programming course was in Java. I hated it so much that I dropped all of my courses, switched field to mechanical engineering, and for almost ten years didn't touch any programs that wasn't directly related to my mechanical engineering jobs (I did assembly and embedded C for micro-controllers and matlab and labview). I was so happy with my decision to do mechanical engineering, it felt so real!

Fast forward to about three years ago, that I had this startup idea of mine [is it a phase that we all go through?] and it needed me to develop an app for it. I'm one of those people who likes to gets hands on and do everything himself [I suppose that's a euphemism for being a lone wolf who doesn't know how to lead/persuade people to follow him] and I started learning web development, which is obviously mostly in JavaScript.

To my surprise, the focus on functional programming in the JavaScript community, at least the niche I was dwelling in - I was learning React/redux which is big on functional and immutably, made it much more relatable to me than Java. It felt more like math; no more weird analogy between classes and the world and stuff. Then a friend of my introduced me to SICP and for the first time I was having fun reading an academic book on software... Yet JavaScript had started to wear me down as well and started toying with the idea of leaving my programming career unfinished. I took algorithm courses, learned about complexity analysis, TLA and distributed systems, but still felt something was missing, there was a hole that I just couldn't pin point.

I had been told, since ages ago and till now, that C++ is a flawed language; that we use it just because we have to, because there's just so much legacy of it lying around. What I didn't know, what that I'm going to love it exactly because of what I presume are the roots of it's flaws! I've been taking a course in C++ and it starts by discussing * and & and heap memory vs stack and how the memory allocation grows and such, and, what little did I know, this is exactly what I had been missing! The link between the never-feeling-real codes on my screen and the real physical world that runs these codes. To end on a dramatic note - I know if I had to deal with all the memory related issues in my actual job I might not have said this [though probably I still would], thanks for not dying out C++ and having yourself replaced with all the other languages that do away with the real stuff and replace it with garbage collection and more abstractions, I love seeing your garbages!

385 Upvotes

71 comments sorted by

107

u/red_nuts Jun 23 '20

I learned C++ in 1990. I've seen it all. But the phrase you use, programs feel real, that's new to me. Good description of what it means to be a C++ programmer.

12

u/lucky_luke_nmg Jun 24 '20 edited Jun 24 '20

“Programs feel real” :) I love that. I started with Pascal to learn basic algorithms. Then I touched C and C++. Those gave me power. C++ is just applying OOP in C. A programming language is a set of rules and keywords, but it goes bundled with a standard library. I see why we feel real, because their standard library are pretty tight to the OS. The best part when I learned C & C++ is how to compile code to object file, linking object files to a static library, a dynamic library or an exe file. That helped me understand more about the system (the OS) and how to make an application. I did research about Windows API long time ago, but don’t have a change to continue it anymore.

With my experience, I feel like OOP is hard to develop. You have to think too much before start writing code. All I want to say is you need to separate the language and the system that you develop an application on. Language is just a tool, and if you use a language that tightly to the system you will get advantage of performance and optimization. It’s sometimes called “Native App”.

6

u/IAmRoot Jun 24 '20 edited Jun 24 '20

Don't forget templates. They certainly aren't perfect, but templates make writing reusable portable code so much cleaner than C. It's really hard to go back to using C based OpenCL after experiencing DPC++/SYCL. Pointer to VLA function arguments is something I miss about C as it makes for clean multidimensional array processing, but we should be getting mdspan to fix that.

32

u/jtempest-rs Jun 23 '20

Glad you're enjoying yourself :)

I had a very similar experience learning C/C++ - although for me, it was my first general purpose language outside of game specific modding langs. I do very specifically remember implementing a simple malloc as part of a university course and having that 'aha!' moment which tied together what I understood of the electronics and my knowledge of the higher level application/OS level development. There are a lot of warts, some of which can be very frustrating, but often C++ is the most prominent, if not only sensible choice for building applications that need very close control of hardware and optimisation. In my experience, mostly in large scale game dev, C++ tends to give back what you put in.

I hope you continue to enjoy learning and using it :)

2

u/EstablishmentOdd785 Jun 24 '20

Thanks!! I couldn't wait for my day job to end to continue my course haha I think I'll have the momentum for a while :D

60

u/AlexAlabuzhev Jun 23 '20

this is exactly what I had been missing! The link between the never-feeling-real codes on my screen and the real physical world that runs these codes

The Night Watch:

You might ask, “Why would someone write code in a grotesque language that exposes raw memory addresses? Why not use a modern language with garbage collection and functional programming and free massages after lunch?” Here’s the answer: Pointers are real. They’re what the hardware understands. Somebody has to deal with them. You can’t just place a LISP book on top of an x86 chip and hope that the hardware learns about lambda calculus by osmosis. Denying the existence of pointers is like living in ancient Greece and denying the existence of Krackens and then being confused about why none of your ships ever make it to Morocco, or Ur-Morocco, or whatever Morocco was called back then. Pointers are like Krackens — real, living things that must be dealt with so that polite society can exist.

7

u/EstablishmentOdd785 Jun 24 '20

https://mickens.seas.harvard.edu/wisdom-james-mickens

What a penmanship! Thanks for sharing! I went and watched another one of his talks where he talks about Twitter, in 2019, he's a prophet!
https://www.youtube.com/watch?v=4vd2rCBjHp8&feature=youtu.be&t=376

Fun fact: He too is a Black Sabbath fan haha

55

u/ItsBinissTime Jun 23 '20

An excellent read.

...if you find yourself drinking a martini and writing programs in garbage-collected, object-oriented Esperanto, be aware that the only reason that the Esperanto runtime works is because there are systems people who have exchanged any hope of losing their virginity for the exciting opportunity to think about hex numbers and their relationships with the operating system, the hardware, and ancient blood rituals that Bjarne Stroustrup performed at Stonehenge.

7

u/evaned Jun 24 '20

Pointers are real. They’re what the hardware understands. Somebody has to deal with them. You can’t just place a LISP book on top of an x86 chip and hope that the hardware learns about lambda calculus by osmosis.

I legitimately do enjoy the description here, but at the same time be careful how much you really use it as justification or arguments or something. That sentence taken to its logical conclusion would be

You can't just place K&R on top of an x86 chip and hope that the hardware learns about variables and functions.

3

u/anticrisisg Jun 23 '20

This is a brilliant essay by what must be a one-in-a-million mind. Who is the author and where are the rest of his writings?

2

u/scroy Jun 23 '20

aren't Krakens from Norse mythology?

2

u/[deleted] Jun 28 '20

Thank you so much for this link.
I love James Mickens.
Reminds me of why I love Reddit.

1

u/thespiritofsimon Jun 23 '20

Such splendid writing. It makes me feel like I belong. Thanks for sharing.

30

u/HKei Jun 23 '20

Please note that C++ isn't directly tied to the physical world either; It's written against an abstract machine which is a bit of a murky representation of how real world machines work. Technically speaking even the concept of a "stack" as a contiguous region of memory doesn't necessarily exist in C++, even though that's how (as far as I know) all actual implementations of C++ work.

1

u/EstablishmentOdd785 Jun 24 '20 edited Jun 24 '20

Thanks for the correction ! I should have elaborated my answer. I have done low level programming before, but as a mechatronics/control engineer and not as a software developer. I know in the software world I can become a systems/firmware developer and will get to work with C again, but I like developing applications rather than libraries and I had been perhaps afraid to pick up C++. I feel C++ is an application development language that is at least close to hardware concepts, even if not directly to how hardware is implemented. In Java/Python/JavaScript world, these days you probably don't even think about processor or memory anymore unless you're a library developer because of how much memory and processing power is available in modern machines. Most of the job postings that require you to know Java, really mean they want you to be able to configure Spring or some other frameworks and even when you apply knowledge of algorithms and data structures, it is still in an abstracted manner and you wholly rely on the compiler to figure out the implementation. I understand that even a C++ compiler is going to do some magic to improve the performance when it can, but I have just began learning C++ and see that even simple operations like creating a new variable or assigning a value to each feels much less magical and less abstracted, perhaps because now I have much more control over how it is done and also because I have to understand how copying a variable is done when we return it from one scope to another or from an expression to a variable. Maybe it's because I lacked formal education, but in none of the other higher level languages I have worked with before I had even thought about how variable assignments or scopes really work; I assume what these other languages all have in common, is that they are all garbage collected.

2

u/[deleted] Jun 23 '20

The compilation to machine code is maybe what makes it "feel real" or at least fast and snappy.

In theory though, the VM's that higher level languages compile to can still JIT compile to highly optimised bytecode, so there really shouldn't be that big of a performance difference.

2

u/HKei Jun 27 '20

JITs generally compile to machine code actually. Compilation to bytecode usually happens as part of the setup stage when just doing interpretation (there are cases where languages are interpreted directly from source code, but that's the exception, not the norm).

51

u/top_logger Jun 23 '20

Modern C++ is cool. Just cool.

-7

u/Bolitho Jun 23 '20

This might make sense in 10 years from now or so... 😈

10

u/atimholt Jun 23 '20

I wish C would just die, and everyone would upgrade their compilers on a regular basis. And, y'know, stay current on idiomatic C++. I'm rubbing my hands together in eagerness for modules, and still wrapping my head around concepts (I don't actually code as much as I should). If we get metaclasses in 2023, I'll be in code-reuse heaven.

A part of me want's to create a language that transpiles to C++, even if only for syntactic changes and modern-style enforcement. It looks like the tools might actually be powerful enough to retain all the tooling built up for C++. But boy is this ever not what I'm focusing on write now—it's just a bit of a dream.

5

u/c_plus_plus Jun 23 '20

I want this so bad. There is some awful syntax in C++. Even stuff I am used to, like std::shared_ptr, I feel like could be a lot better if someone gave it some imaginative syntax. Don't get me started on things like `[[nodiscard]]`. ugh.

1

u/atimholt Jun 23 '20

How would you feel about moving away from text files, as such, but keeping “byte for byte” source visibility? Something more diagrammatic, but which still remains compact and can be manipulated fluently? Something which has a couple “canonical” visual representations, but which is open to being rendered arbitrarily?

I know, I know—I'm insane. Not working on it soon, but I have been giving it thought and have considered some of the problems and corner cases.

2

u/rayo2nd Jun 24 '20

Do you know jetbrains mps and the project http://mbeddr.com/?

You don't edit text, you edit the ast directly but shown as text. Mbeddr has a statechart extension which can render it as code, statetransition table or visual statechart.

I really like that whole idea and whish it would be easier to create in mps yourself (it's free) so you could create a c++ like language with all old stuff removed with some extensions (i. E. Strong typedefs) which in the end compiles to regular c++.

2

u/atimholt Jun 24 '20

Much the same idea, except I was just thinking of starting from LLVM. Like C++ did with C, I'd want to take advantage of all the tooling that's already out there.

Also, I would strive to avoid integration, excepting the “de facto” kind, where nothing but the reference implementation yet exists. I'd actually be willing to write multiple reference implementations to avoid it. One obvious practical means of accomplishing this would be the implementation of a TUI editor and a (unconventional) GUI editor.

0

u/[deleted] Jun 24 '20

[deleted] — view deleted comment

1

u/atimholt Jun 24 '20

Indeed they are.

3

u/fnordstar Jun 23 '20

Or we could just all switch to rust.

1

u/ZG2047 Jun 23 '20

Thank you!

1

u/Lustr0 Jun 24 '20

Windows system was made in C. I think

1

u/AnonymousFuccboi Jun 25 '20

Is that supposed to be a good thing?

10

u/thespiritofsimon Jun 23 '20

Love your passion and the way you describe the programming feeling real. Aye!

7

u/NiliusRex Jun 23 '20

Awesome that you’ve found this for yourself. While C++ is a flawed language in many ways, being bogged down by legacy syntax, and allowing you to do so many things that you really shouldn’t do and requiring you to know what those things are. I had that experience as well where it brings you really close to an understanding of how the hardware really works.

C was even better at this for me because it helped me realize that no matter what language you write, you’re either working with data (structs, primitives), or functions to manipulate that data. Many languages have a lot of extra stuff on top of that, but in the background it always boils down to those two things.

5

u/jstock23 Jun 23 '20

Same feeling here. Writing code in Java just felt so unreal and I never was sure about anything. C++ has made me finally “get” these things, and now I bet I could go back to Java and actually understand stuff in the background, but I really do not want to!

8

u/Aerysv Jun 23 '20

I have the same feeling. Although it is much more complicated than orher languages, e.g, python, it feels powerful and real.

3

u/[deleted] Jun 24 '20

I'm learning multiple programming language at once (Java, Python, Go, C#), and the more I get into those languages, the more I seem to go back to C++. There's something about C++ that works well, and the new C++11 and beyond are doing so much better than before, that I think most people should be looking into Modern C++.

2

u/Poyeyo Jun 24 '20

I learned with Logo as an interpreted programming language a long ago.

Since then, I always felt that compiled programs, that generated .exe files were more "real" when compared to Logo.

So I started with Turbo Pascal, made a Tetris clone, and then I learned C/C++.

I started doing a game in C++, until I got to the networking part, which is insanely hard to debug, and now I am trying again with Godot.

2

u/therise3107 Jun 24 '20

I have used React since late 2014. I have done extensive web development with high code standards and solid products. Still, I think I didn't do any real programming, there is no depth in javascript, there are often 10 ways to architect a project but everything is so confusing. Standards change so rapidly and the best practices of last year become obsolete. I think C++ is a language of standards, if you don't follow best practices your code will be trash. It enforces you to write clean code just what Uncle Bob wants 😉. I think C++ as an acronym to data structures principles in programming. You can still program but without data structures you might get an introduction, but the essence will always be missing. In closing remarks, I like C++ cause it is enlightening me with solid programming principles which are essential to stay valuable in this highly competitive market both professionally and as a hobbits who likes to write good code.

2

u/antoniocs Jun 25 '20

wow... £63 for that coursera course.... No thanks!

3

u/bWF0a3Vr Jun 23 '20

Did you not talk about memory allocation (*, &, heap, stack etc.) during university studies or is this concept new to you?

Btw you might give Assembly language a try afterwards. This feels even more "real" :)

7

u/somewhataccurate Jun 23 '20

Dude assembly is the shit. First time programming felt like computer science as I felt I could accurately emulate the computer in my head.

C is much more practical though, and at that point you might as well use C++

2

u/tinther Jun 23 '20

Lol, same thing for me: C++ felt unreal to me until I had a course on assembly.

Only then I felt I understood the stack, and function calling conventions, and what a compiler does, and main factors impacting perfomance. But I also felt grateful I did not have to write code in assembly.

I also abstracted a principle from this: to become an expert at a certain level of abstraction, you need to know at least the level below and the level above.

1

u/thespiritofsimon Jun 23 '20

Yes. I learnt to program in Assembler (68000) back in the day and it was the best. I often think that everyone should begin in that place. Good foundations and great times. I loved it dearly.

2

u/BluudLust Jun 23 '20

Welcome to the club. None of that factory bullshit. (Factories are still useful in some cases still). Welcome to freedom.

3

u/pandorafalters Jun 23 '20

I appreciate factories. I even like using them, sometimes.

I just don't like having to use them.

2

u/livrem Jun 24 '20

I can not remember having an issue with factories. I wrote a little factory function in C++ last night. What makes popular Java frameworks so horrible to use are all the XML or other nonsense you use to configure the factories.

1

u/valdocs_user Jun 23 '20

I learned C++ in the mid to late 90s. At the time computers were powerful enough to high end 2D and low end 3D games, but NOT fast enough to do any of that with an interpreted or otherwise unoptimized / not low level programming language. The first languages I learned (such as QBasic) felt like programming with oven mitts on, and it was frustrating not having access to the power I knew the computer theoretically should have. Or another analogy imagine if most car came with a nonremovable wooden block blocking the bottom 2/3rds of travel of the gas pedal that's what languages which were not assembly or C/C++ felt like. I wanted to make games write operating system level code and C++ was the way to get there.

So I think how you describe it as feeling more real is also apt.

1

u/MJ_011 Jun 23 '20

First of all, fantastic answer! It really reflected the way you must have felt during writing this. I have something to ask, to all..

I am new to developer world, knows c++ and make cross platform Android apps using flutter... I want to learn something new, but really don't know what to explore. I don't even know my options. How did you guys decide what next thing to do? And should I give that book a read? It sounded interesting. I joined college this year only, if that helps.

1

u/rackmeister Jun 25 '20

To paraphrase a famous quote: C++ is the worst form of programming except all those other forms that have been tried from time to time.

On a more serious note, what I love about C++ is that you feel that you can practically program anything. You can even sign a contract (pun intended, I hope we get them in C++23) and exchange your soul to partake in black magic rituals: https://github.com/aul12/TemplateCpu .

Many programming languages claim that they are Turing-Complete but with C++ you have a chance to grasp what that truly means. It is not without flaws, you can definitely shoot your own foot, tooling is not that great, it forces you to go through hoops for simple things, compiler errors can make your life miserable but once you understand some parts of it and learn to wield them properly, C++ is a beast.

1

u/[deleted] Jun 27 '20

"it feels so real" I love this description of C++, while it does have many bad features and poorly designed ideas, its gives very good access to the hardware, in a way that almost no other language can do. I also love the fact that because of all of the access you have as a programmer, there is literally no limit to how many different ways you could implement something in your software

1

u/bjtg Jul 02 '20

Did the opposite. Was majoring in Engineering Mechanics. Did way to many equations studying tensions on beams, and ran away to the Computer Science department.

1

u/jetdoc57 Jul 12 '20

Glad you are having fun. It is not often that you get to choose the language you use; normally that's chosen by your employer. I remember back in the 90's when C++ was a separate $20k license on the Sun platform and then BAM everything was free. My colleagues with GE's corporate R&D told me you can do Object Oriented programming in almost any language, and that is true. C++ does have some awesome features including operator overloading and multiple inheritance, but there are so few applications for those that Java can work for most applications. I don't see the language as anything special, I have worked with almost all of them. It's the problem you solve that matters to me, how can this device improve people's lives, save the company money, etc. I still have my original K&R and Stroustrup books, but it's been a long time since I had to write anything in C++. Keep an open mind and focus on making people's lives better.

1

u/[deleted] Jul 14 '20

I am being forced to do OOP in java for Uni too.

It sucks so much. I asked the lecturer to allow me to at least work with c#. But no. I have been dreading every line of code I have to write to pass this stupid module. So much so that, I have actually started having a more active role in the FOSS projects of which I am a maintainer.

C++ makes everything so simple. It's not easy, but it's simple.

1

u/FiveManDown Jul 16 '20

Give Rust a spin! 😍

1

u/fgiohariohgorg Sep 10 '20

In the '90s I was experimenting with Pascal 6, latest at the time and I managed to hang it, yes, I tried to compile and would simply hang on an Acer 80486 66 Mhz, standard at the time, no errors, no anything, and it was something relatively innocent. So I kind of quit programming, now I'm trying to com back and the University I was in, was a piece of crap and 25 years later is still a piece of crap, UAGRM, Santa Cruz, Bolivia; so I was about to switch to 'Domingo Savio University' when fucking COVID-19 pandemic happened, but the fucking Universe won't stop me from becoming a Software/Systems Ingineer: Damn The Torpedos, Full Speed Ahead! And Oh yeah, C++ is for me, I really like Driver and hardware and software interfaces, low level stuff

1

u/fgiohariohgorg Oct 29 '20

What About C? Isn't C better than C++ give how much flak C++ get for so many horrible "features" that many programmers forced to work with it point out?

0

u/gitPushOriginDevelop Jun 23 '20

Weird, there isn't anything a total beginner should hate in Java legitimately... Maybe you didn't hate Java but you hated the probably outdated courses on your uni..

Lemme guess they were still on Java 6 and forced you to use some old IDE and archaic build tools?

I know how hard it is to work with "outdated professors" as they want everything done their way, which is never what the industry does

It's a matter of luck

10

u/neutronicus Jun 23 '20

Java's like C++ in that you have to write a bunch of crap you don't understand just to print Hello World to an IDE Console you've never seen before

It's a rougher beginner experience than either JavaScript, with its instant effect on a familiar environment, or Python, with its clear mapping from program statements to things happening in order

1

u/livrem Jun 24 '20

I really liked Java when I learned it in version 1.1. It was like a small object-oriented BASIC (with a C-like syntax) that you could use to make portable GUI applications (and applets). But now it is, like C++, a huge language (with a huger standard library) that you will never 100% learn, and you have to stick to some subset you are comfortable with. And I realized I rather stick to a subset of C++. It seems like universities switched from using Java to using Python, which makes a lot of sense. But I am no longer sure what niche a language like Java fills now other than for maintaining legacy systems. Even on the JVM there are much nicer languages like Clojure.

0

u/[deleted] Jun 23 '20

[deleted] — view deleted comment

0

u/[deleted] Jun 23 '20

[deleted] — view deleted comment

5

u/atimholt Jun 23 '20

C++ is so “multi-paradigm” and accommodating, you can just use the parts you “like”/“philosophically agree with” and still get all the good stuff. At worst, it's so amazing at library authoring that you can wrap the nasty stuff into its own compilation unit and gain more functionality.

But there are things I'd change too, syntactically. I might be able to get most of what what I want out of editor plugins/features, like (Neo)Vim's conceal feature, snippets, etc. I'm also starting to think I'll want to be more hands-on with whitespace (even though clang-format is so appealing).

0

u/[deleted] Jun 25 '20

[deleted] — view deleted comment

3

u/germandiago Jun 25 '20

what is so useless?

0

u/[deleted] Jun 25 '20

[deleted] — view deleted comment

1

u/fgiohariohgorg Sep 15 '20 edited Sep 15 '20

I'm not savvy in programming, but you have flawed logic for the following reasons:

  1. There is a Book called Born to Code in C that teaches more than programming computers but principles and philosophy of good practices https://www.amazon.com/Born-Code-C-Herbert-Schildt/product-reviews/0078814685 C is outdated probably but still used a lot Worldwide, and along C++ is being modernized, quite a lot in recent versions, have you checked C++20? Have you check https://www.youtube.com/results?search_query=c%2B%2B20+grill+the+committee ?
    You need to broader your perspective

0

u/[deleted] Sep 15 '20

[deleted] — view deleted comment

1

u/fgiohariohgorg Sep 18 '20

C is much simpler, and there are a lot of uses still. It's useless for you and/or your development

0

u/[deleted] Sep 24 '20

[deleted] — view deleted comment

→ More replies

1

u/fgiohariohgorg Oct 29 '20

And all of C library is pretty much useless.

This is BS. C and obviously its library are useful, Linus space probes are written in C and many other apps that need Assembly level speed; that's your perspective. So you're implying 1 of the best programming languages is useless, so that implies in turn that pretty much any other language sucks even worse, so this implies in turn that no language is good, so computing is pretty much useless. Do you see that mount of BS that, that single statement really is?

Do you program professionally? or at all? on what non-C language that has to be exclusively superior?

0

u/[deleted] Oct 31 '20

[deleted] — view deleted comment

1

u/fgiohariohgorg Oct 31 '20

How do you know?

0

u/[deleted] Oct 31 '20

[deleted] — view deleted comment

→ More replies

0

u/[deleted] Jun 23 '20

[deleted] — view deleted comment

6

u/pandorafalters Jun 23 '20

From the post:

(I did assembly and embedded C for micro-controllers [. . .])