C or C++: Which is the language you prefer?

3    08 Sep 2016 12:22 by u/Omnipresent

36 comments

9

C is fundamentally a subset of C++. If you simply restrict yourself to a subset of capability, you can treat C++ exactly like C. C# vs C++ is where fundamental differences start to come into play.

If you're consider which language to learn I'd always recommend going from the bottom-up: assembly, C, C++, C#. This is not commonly recommended since the lower level languages are quite challenging to wrap your head around for a new developer, but if you can manage it you'll achieve a far greater understanding of niceties each language gifts you with and their underlying costs that can allow you to develop far more robust and performant programs than somebody who started at the top.

1

C# is more advanced than C++? :o

6

yeah, absolutely not haha

5

C# is more closely related to Java than C++. It's easier deal with than either of those in my opinion, but that's really up to personal preference. Up until recently you were locked into Microsoft's playground if you wanted to use it with any real support, the Mono project notwithstanding, so a lot of people have avoided it for that reason. I can't really blame them given Microsoft's tendency to hold out an olive branch only to shoot you if you go to grab it.

1

C# is C++ with training wheels. Assembly is definitely the most difficult to use on that list. I think that's why he listed them that way.

2

Opcodes, just saying.

1

I know what they are, just not sure what you mean in this context.

2

Assembly is the mnemonics for opcodes, you can calculate out each op code ahead of time then fire it into instruction memory for really fast results. You'd be basically doing Assembly to machine code by hand. Only really a thing you'd see in embedded programming when you have to shave off any unnecessary clock cycles where resources are extremely scarce or when your brand new x86 processor is being evaluated in the lap only to discover that certain instructions are returning incorrect values and you need a bit of microcode to correct it (also happens with GPUs all the time).

1

I'd never use the word advanced since it's going to bring out the "strongly opinionated fans" of one language or the other. I ordered them in terms of "What, why can't I [do thing from other language]?" You're never going to find yourself missing a feature from assembly in C. You're never going to find yourself missing a feature from C in C++. And you're [almost] never going to find yourself missing a feature from C++ in C#. There are a couple of exceptions there like neat things you can do with templates such as template meta programming, and things that are nasty as like multiple inheritance, but in general it's true. C# was designed to take the best of a variety of languages including C++, Smalltalk, and Java and create a modern language featuring all the strengths of those languages while minimizing their individual weaknesses. It's for this reason that you'll find updates to the C++ standard regularly borrowing things that are already present in C#. It's also for this reason that having a very good understanding of what's being abstracted away, like memory management, is absolutely crucial.

0

The university I went to taught C, then C++, then Assembly. Then they went to Java for some reason...

0

I started with C for desktop, then Assembly for PIC, two separate C for PIC courses, then in at the deep end with no resources Java for desktop cause that makes sense. Next year its more C for PIC and then Java / Android app development just to fucking annoy us (I think we'd get more mileage from a.Linux Bash / embedded os intro than we would an android app).

1

But apps are the wave of the future! We need to teach everybody app development!

- Some idiot, probably.

I agree with you. Programming degrees should focus on the basics. Then students can branch out from a solid core instead of knowing parts of all the branches and none of the roots. I mean, you can't navigate a binary tree from a random node, you have to start at the root node. The same applies to learning how to program.

1

Thats actually something the idiot behind this nonsense started saying in the final few weeks of last years classes. He really is a moron but like one of those clever morons that thinks that we should all be on the same page as him because he has been doing this as a career since the late 90s and doesn't think its particularly hard.

Hes that guy that pushes everyone around him to use Linux and acts like you can be on par with how you'd use Windows overnight because again hes been using it since the late 90s and its ingrained knowledge to him, you know that kind of snobbery of how much more superior Linux might be while ignoring the fact that doing anything more advanced than browsing the web can be a real struggle just trying to find valid information on how you'd go about fixing the problem can take a lot of time as well as trial and error. He'd know that he can do this, this, and that to fix the problem were as a novice would putter around trying to find out how to start the few first steps. Some people are just totally unaware of how many niche things they know and how much effort its taken for them to gain that knowledge.

0

Why pic instead of avr, may I ask?

1

AVR micros get a but funny when you accidentally change a port fuse and nuke a port pin. Arduino stuff was introduced to us last semester and theres nothing wrong with it or AVR micrcos but using Arduinos native language would hog up a lot of program memory space if you wern't careful when things got more elaborate than flashing LEDs and needed a internet connected sensor that also had a user interface so some of us learned a little AVR C as a way to save an awful lot of program space, quite a few of us managed to permanently damage their microcontrollers very quickly.

PIC also uses one really well developed, really powerful, really helpful tool called MPLAB where we could simulate most if not all of a supported PIC's functionality before programming it meaning you can get really nitty gritty over usage of program or instruction memory. Theres a like for like equivalent for AVR but those fuses potentially a nightmare for my colleges lectures and maintenance.

6

This. I don't like that in most universities they teach you first stuff like Java and the like, and then move to lower level. You need to understand how the computer works internally to be able to program good imho, and high-level programming languages teach you the other way around. They are very useful, but once you know how the lower bits work!

3

I also believe that all programming degrees should require a course on compilers. That was seriously the most helpful class I took at university, it really tied together a lot of the random bits and pieces of knowledge I'd accumulated up to that point, and it allows me to write better code because I understand how compilers work now.

6

C!

To hell with this newfangled nonsense they call object orientation! That's just another hype that won't catch on. I like to know my pointers and bits in memory.

1

OOP is nothing more that passing a pointer to a struct as a first parameter named "this." People already developed OOP code in C,

That WINAPI handle you have been passing on? It is basically OOP the only difference is its notation. Syntax sugar.

4

Depends on the task. Programming languages are tools and for best results use the best tool for the task.

0

Which do you think is more valuable, then? lol

7

I'll go with C. But it's not a big difference.

3

I usually use c++ for anything i need classes for. Otherwise I use c (although I use fortran more often)

0

curious, why fortran?

1

It's just what I've been using for anything that doesn't require classes. Started using it for LBM simulations, very straightforward to learn, it's fast, and easily parallelized.

2

I do prefer C, because of a better control over the program flow and memory, but C++ got nice features ( templates and namespace come to mind ), additionnally C force you to write a lot of boilerplate code.

C++ compiler also tend to get a lot of liberty with your code, and all C++ features can make the intent of the code unclear ( object oriented language tend to have unforseen side effects, operator overloading can differ from the initial intent, like "<<" & ">>" over streams ).

2

I'm late to the party but... C. I have no idea why people choose C++ over it. All I ever see from C++ is a horrible mess of syntax. I/O with <<. Unknown sorts of statements with : and ::. Other unknown statements with <> in them. Worse than the most horrible mess you can make with the C preprocessor.

1

C++

I cannot function without object oriented programming.

1

C++ purely because, in my experience, the code is more readable. I'm sure there are arcane examples of both however.

1

Classes are horrible.

C++ added some other things that are very good such as the tools for semi-automated memory management, but overall the language is way too large. It requires a lot of discipline on the side of the development team and a strict code guideline so I prefer C.

1

C++. Anyone who dislikes OO programming is stuck in 1994.

1

I absolutely hate OO and I wasn't even programming in 1994. Interfaces are ok, but don't go far enough (type classes are more powerful and useful) but subtype polymorphism is just cancer. Attributing ownership of functions to datatypes is only reusable if you introduce internal states, which is a huge cause for bugs in major projects. Internal states should be reserved for very few things like thread-safety and encapsulated into explicit contexts, instead of that in OO every single object potentially has hidden internal state.

1

C/C++ is basically the same thing, just compiler that toys with the notation but under the hood it is the same end result. When you look at the assembler code then in case of C++ the first parameter is the reference to the object.

The big question is what do you prefer:

Save(fileHandle,"c:\foo.txt"); 

or

fileHandle.Save("c:\foo.txt"); 
1

The right tool for the job. OOP is very helpful for expressing business logic. If you are writing a fixed set of instructions, something like take this string and send it via SMTP, then you might as well stay with C.

You can easily emulate OOP in C, but nobody wants to write all that extra code.

1

It depends on usage, for PC programming C++ becouse of object oriental things. But for microprocesor programming I prefer C.

1

I prefer C over anything else. The only good thing C++ has ever done was distract mediocre programmers from leaning C.

"Oh well C++ is just an extension of C, it can do everything C does and more..." is a fucking retarded statement. That's like arguing a 13 wheel car is inherently better than a 4 wheel car.