• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 12:31
CET 18:31
KST 02:31
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10
Community News
Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2BGE Stara Zagora 2026 announced15[BSL21] Ro.16 Group Stage (C->B->A->D)4Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win3RSL Season 3: RO16 results & RO8 bracket13
StarCraft 2
General
Chinese SC2 server to reopen; live all-star event in Hangzhou Maestros of the Game: Live Finals Preview (RO4) BGE Stara Zagora 2026 announced Weekly Cups (Nov 24-30): MaxPax, Clem, herO win SC2 Proleague Discontinued; SKT, KT, SGK, CJ disband
Tourneys
Sparkling Tuna Cup - Weekly Open Tournament RSL Offline Finals Info - Dec 13 and 14! StarCraft Evolution League (SC Evo Biweekly) RSL Offline FInals Sea Duckling Open (Global, Bronze-Diamond)
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 502 Negative Reinforcement Mutation # 501 Price of Progress Mutation # 500 Fright night Mutation # 499 Chilling Adaptation
Brood War
General
BW General Discussion Which season is the best in ASL? Data analysis on 70 million replays BGH Auto Balance -> http://bghmmr.eu/ [ASL20] Ask the mapmakers — Drop your questions
Tourneys
[Megathread] Daily Proleagues [BSL21] RO16 Group D - Sunday 21:00 CET [BSL21] RO16 Group A - Saturday 21:00 CET [BSL21] RO16 Group B - Sunday 21:00 CET
Strategy
Current Meta Game Theory for Starcraft How to stay on top of macro? PvZ map balance
Other Games
General Games
Stormgate/Frost Giant Megathread ZeroSpace Megathread Nintendo Switch Thread The Perfect Game Path of Exile
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Mafia Game Mode Feedback/Ideas TL Mafia Community Thread
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine The Big Programming Thread Artificial Intelligence Thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
[Manga] One Piece Movie Discussion! Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Where to ask questions and add stream? The Automated Ban List
Blogs
Physical Exertion During Gam…
TrAiDoS
James Bond movies ranking - pa…
Topin
Thanks for the RSL
Hildegard
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1458 users

The Big Programming Thread - Page 273

Forum Index > General Forum
Post a Reply
Prev 1 271 272 273 274 275 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
nunez
Profile Blog Joined February 2011
Norway4003 Posts
March 18 2013 22:34 GMT
#5441
On March 19 2013 07:21 CecilSunkure wrote:
Show nested quote +
On March 19 2013 07:15 MiyaviTeddy wrote:
... snip ...

You should look up inheritance and polymorphism, along with pointers and typecasting.

If you know these then you can see A is treated as a base for other derived cases. The derived cases override a base function being called from A base pointers.


B doesn't override f, it overloads it. B's f will not be called.
conspired against by a confederacy of dunces.
Ilintar
Profile Joined October 2002
Poland794 Posts
March 18 2013 22:37 GMT
#5442
On March 19 2013 05:36 CecilSunkure wrote:
Show nested quote +
On March 19 2013 05:26 Ilintar wrote:
Agreed - coding OOP in C is like coding lambda abstractions in Java - might be fun or useful as an exercise, but in both cases there are simply languages better suited for the job.

OOP in C was actually the language of choice for a lot of GBA games. But again the point isn't to learn it professionally, but just to have a solid understanding of how what you're using in C++ works. Using function pointers and typecasting in C for OOP isn't as difficult or tedious as you guys seem to think it is.

On a different topic, if I could I'd code everything in C instead of C++. I really like C. It's just that templating in C++ is so useful, and there are some very nice C++11 features coming around. Whenever someone codes something in C it's almost always completely obvious as to what they are trying to do. With C++ though there are a lot of ways to hide a lot of things. Auto-generated code, things can be run in non-intuitive ways. It's a big problem when a poor C++ programmer is writing code within a team. Of course the solution isn't "lets all code in C", it's just to use C++ appropriately. Even at my school though it's hard to find solid programmers to work with. I can't imagine how hard it would be to find a fit for a team that works primarily with C++ out in the world. Perhaps if more people started "hitting the ground running" in C things would be different?


The problem is, miniscule optimization gains that you get by coding stuff in C over C++ (miniscule because both langauges are compiled, native languages, so the code will compile to basically the same assembly with a proper compiler, minus vtables and OOP-specific stuff, plus the C++ compiler can optimize a lot of OOP code that the C compiler cannot) is lost by programmer hours. C++ has type-checking for all sorts of OOP stuff that C does not - by definition, if you typecast pointers, you are basically telling the compiler "I know what I'm doing, I told you before that this was stuff of type Foo, but it's really stuff of type Bar". So the compiler will basically tell you "okay, but don't complain later when you get a segfault since you reference a non-existing function poiner". The issue here is, pointer arithmetic is notoriously hard to debug and takes away tons of valuable programmer time. Agreed - there are times when you need to do OOP-style programming in C and Linux kernel drivers are a fine example, but then again, most people don't program Linux kernel drivers. In normal, user-land applications, there is really not reason nowadays to use C over C++ if you want to do OOP.
Former webmaster @ WGTour.com / BWLauncher developer
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
March 19 2013 00:05 GMT
#5443
On March 19 2013 07:37 Ilintar wrote:
Show nested quote +
On March 19 2013 05:36 CecilSunkure wrote:
On March 19 2013 05:26 Ilintar wrote:
Agreed - coding OOP in C is like coding lambda abstractions in Java - might be fun or useful as an exercise, but in both cases there are simply languages better suited for the job.

OOP in C was actually the language of choice for a lot of GBA games. But again the point isn't to learn it professionally, but just to have a solid understanding of how what you're using in C++ works. Using function pointers and typecasting in C for OOP isn't as difficult or tedious as you guys seem to think it is.

On a different topic, if I could I'd code everything in C instead of C++. I really like C. It's just that templating in C++ is so useful, and there are some very nice C++11 features coming around. Whenever someone codes something in C it's almost always completely obvious as to what they are trying to do. With C++ though there are a lot of ways to hide a lot of things. Auto-generated code, things can be run in non-intuitive ways. It's a big problem when a poor C++ programmer is writing code within a team. Of course the solution isn't "lets all code in C", it's just to use C++ appropriately. Even at my school though it's hard to find solid programmers to work with. I can't imagine how hard it would be to find a fit for a team that works primarily with C++ out in the world. Perhaps if more people started "hitting the ground running" in C things would be different?


The problem is, miniscule optimization gains that you get by coding stuff in C over C++ (miniscule because both langauges are compiled, native languages, so the code will compile to basically the same assembly with a proper compiler, minus vtables and OOP-specific stuff, plus the C++ compiler can optimize a lot of OOP code that the C compiler cannot) is lost by programmer hours. C++ has type-checking for all sorts of OOP stuff that C does not - by definition, if you typecast pointers, you are basically telling the compiler "I know what I'm doing, I told you before that this was stuff of type Foo, but it's really stuff of type Bar". So the compiler will basically tell you "okay, but don't complain later when you get a segfault since you reference a non-existing function poiner". The issue here is, pointer arithmetic is notoriously hard to debug and takes away tons of valuable programmer time. Agreed - there are times when you need to do OOP-style programming in C and Linux kernel drivers are a fine example, but then again, most people don't program Linux kernel drivers. In normal, user-land applications, there is really not reason nowadays to use C over C++ if you want to do OOP.


I really don't want to get back into this age-old Language A vs Language B argument, so let's just say that each has their benefits and drawbacks, and a good programmer should be able to choose the best language to fit the problem.

What actually is worth discussing is the implementation specific differences between C and C++, and why you would use one over the other. Please don't take this as an assault at you, or at C++, I am just trying to clear up a few misconceptions before others read them and take them for truth.

Misconception A: C++ is as fast as C, because they are both static typed compiled languages
+ Show Spoiler +
Currently, there is a phenomenon known as the "C++ tax", which is, in effect, the overhead in using C++ over C to implement a data structure or algorithm. It isn't much, but it's there, and in plenty of applications, that is enough to warrant using C. Simple examples will compile to roughly the same assembly, but if you use templates or make excessive use of inheritance, then the overhead of C++ goes through the roof. You'll note that those are two of the biggest "advantages" C++ has to C as far as OOP goes. They are also the biggest performance drawbacks.

I have benchmark data from my company's compiler running Adobe's C++ Test Suite to support this. We recently reduced this tax by a large factor with recent optimizations, but for real-world cases, the C++ tax is still very real.

I wont release the specific numbers, but here are two commonly used sorting algorithms that were 3x faster in C until recently.

Vector Sort A 2.9 – 3.0x
Vector Sort B 1.6 – 1.8x


Misconception B: Pointer logic makes OOP in C harder to debug
+ Show Spoiler +

"Pointer magic", as I like to call it, is the method of using pointers to functions, and applying those functions later. When doing this, you end up seeing really crazy function calls which are hard to revoke and end up causing confusion because you aren't even sure which function is being called. So, in effect, C is harder to read than C++.

But is it harder to debug?
+ Show Spoiler +
No, duh.

The tools behind developing for C have been advancing at a breakneck speed for decades now. There is capability in debuggers to step through this sort of program design, and tell you which function it's expecting to be there, then step into that function, knowing the values of everything passed through, etc.. We have an effective technological way to "read" our way through a C program rather well. C++ too, but it benefits less because of this, because in C++, the problem is not that the code isn't readable, the problem is that C++ code can lie through its teeth at you without the debugger picking it up.

Well, C++ is more readable, especially when it comes to OOP, but with modern tools, C is pretty debuggable as well. What it really comes down to is the time it takes to identify, fix, and test after identifying a bug. The old adage that C++ gives you enough rope to shoot your whole leg off or something is dead-on. I only have anecdotal evidence, but it usually takes 3-4 times as long to identify a bug in C++ as it does in C. It takes less time to fix in C as well, because compile times are usually only a fraction of the time for the same size program, and generating a test is also quicker. Effectively, the maintenance cycle for C is much tighter, and thus, easier to work with.


Misconception C: No one writes Linux kernel drivers
+ Show Spoiler +
The embedded market is enormous. There are way more microchips in this world than there are PC's. Even with the choice of using C++ in an embedded system, most developers opt for using C because its faster to write a program to do what you want, easier to debug when it doesn't do what you want, and faster running as well. It also takes less space and thus can be ran on cheaper microchips.

I won't go on to where the OOP feature of C can be seen on other platforms, but you can imagine that its not isolated into just one market. C is pervasive everywhere.


With that being said, I wouldn't dream of writing something like a game in C, because that isn't what it is good at. Still probably wouldn't use C++, but that is personal preference, and nothing against the language.

Source: I am an support engineer at an compiler company
Any sufficiently advanced technology is indistinguishable from magic
Ilintar
Profile Joined October 2002
Poland794 Posts
March 19 2013 00:19 GMT
#5444
I agree with you, however, note that I was explicitly speaking about userland stuff. All of the things you described are quite valid within kernel land (and mission-critical code such as eg. game engines) but not usually relevant in userland code.

As for the drivers, you might be right, I did underestimate the embedded market.

Regarding debugging C code vs C++ code - sorry for using a mental shortcut, I meant not just the debugging process per se, but the entire bugfixing process. It's a simple matter of the compiler simply not informing you that you wanted to cast the foo_t pointer to bar_t, not to baz_t (and baz_t is very similar to bar_t, but lacks a single function pointer at the end that is only used in very specific situations). Any time you have to rely on the programmer's know how instead of the typing system, you are bound to spend more time fixing bugs. After all, that's the main reason low-level languages like C were pretty much abandoned in userland in the first place.

Finally, I also don't want to revisit Language A vs Language B wars and I fully agree that one must pick the right language for the job. What I'm simply saying that, unless your job involves very fine-tuned optimizations, for OOP applications C++ beats C. The fact that it's possible to hack OOP related stuff into C doesn't mean that C is as well suited natively for OOP programming as is C++ (or Java, or Ocaml, or any object-oriented language).
Former webmaster @ WGTour.com / BWLauncher developer
Ilintar
Profile Joined October 2002
Poland794 Posts
Last Edited: 2013-03-19 00:35:11
March 19 2013 00:33 GMT
#5445
For example, imagine the following scenario:

typedef struct { void (* do_one_thing)(), void (* do_another_thing)(), void (* do_a_third thing)() } foo_t;
typedef struct { void (* do_one_thing_differently)(), void (* do_another_thing_differently)(), void (* do_a_third_thing_differently)() } bar_t;
typedef struct { void (* do_one_thing)(), void (* do_another_thing)() } baz_t;

...

foo_t **array_of_foo_ts;

...

baz_t **array_of_bar_ts = (baz_t **)array_of_foo_ts;

*(array_of_bar_ts[1]->do_one_thing_differently)();

Now, this will be perfectly valid code, what's worse - it'll even probably work, since baz is shorter than bar, so you won't run out of the array. However, what this call will do is in fact call array_of_foo_ts[0]->do_a_third_thing() instead of the intended action. Now, if those functions are computations with side effects that are relevant much further in the code, such stuff will be extremely hard to catch and debug. Obviously, in C++, the compiler would prevent this from happening (as you'd likely have bar_t inherit from foo_t).
Former webmaster @ WGTour.com / BWLauncher developer
MiyaviTeddy
Profile Blog Joined October 2008
Canada697 Posts
March 19 2013 03:15 GMT
#5446
Guys, I need some help.

So I need to define several classes.
-Abstract class called Account that defines 2 virtual functions.
-Concrete class called VIPAcc
-Concrete class called SavingAcc
-Concrete class called CheckingAcc
All three concrete classes extending the base class Account.

My question is: How do I implement these files as a multi-source project? I was given a main function and I see the

#include "SavingAcc.h"
#include "CheckingAcc.h"
#include "VIPAcc.h"


but where does the Account abstract class go? I feel like I'm almost there. Help would be appreciated! actually, anyone who can skype/irc me to help out with my assignment would greatly be appreciated as well.

I swear to god this is my goto place for any programming help. I feel so bad for coming back here often.
Aiyeeeee
Wry
Profile Joined October 2011
Canada25 Posts
March 19 2013 03:31 GMT
#5447
All your concrete classes inherit from the abstract class, so
#include "Account.h"

in your concrete class headers will suffice, since only your concrete classes need to "know" about the abstract class (unless your main also does for polymorphism, which I don't think is in the scope of your assignment.

Also remember to have include guards.
MiyaviTeddy
Profile Blog Joined October 2008
Canada697 Posts
March 19 2013 03:38 GMT
#5448
On March 19 2013 12:31 Wry wrote:
All your concrete classes inherit from the abstract class, so
#include "Account.h"

in your concrete class headers will suffice, since only your concrete classes need to "know" about the abstract class (unless your main also does for polymorphism, which I don't think is in the scope of your assignment.

Also remember to have include guards.


What are guards?
Aiyeeeee
Release
Profile Blog Joined October 2010
United States4397 Posts
March 19 2013 03:52 GMT
#5449
Hi. Current junior in high school and am thinking about a future in programming.

Which majors/colleges should I be looking into?
+ Show Spoiler +

I know that CMU/MIT/Standford are the three of the best but what are some others?
☺
JeanLuc
Profile Joined September 2010
Canada377 Posts
Last Edited: 2013-03-19 03:53:37
March 19 2013 03:53 GMT
#5450
On March 19 2013 12:38 MiyaviTeddy wrote:
Show nested quote +
On March 19 2013 12:31 Wry wrote:
All your concrete classes inherit from the abstract class, so
#include "Account.h"

in your concrete class headers will suffice, since only your concrete classes need to "know" about the abstract class (unless your main also does for polymorphism, which I don't think is in the scope of your assignment.

Also remember to have include guards.


What are guards?


I typed in 'c++ guards' into google. It brought me this link: en.wikipedia.org/wiki/Include_guard

not bad... not bad at all!
If you can't find it within yourself to stand up and tell the truth-- you don't deserve to wear that uniform
MiyaviTeddy
Profile Blog Joined October 2008
Canada697 Posts
Last Edited: 2013-03-19 04:44:39
March 19 2013 04:16 GMT
#5451
On March 19 2013 12:53 JeanLuc wrote:
Show nested quote +
On March 19 2013 12:38 MiyaviTeddy wrote:
On March 19 2013 12:31 Wry wrote:
All your concrete classes inherit from the abstract class, so
#include "Account.h"

in your concrete class headers will suffice, since only your concrete classes need to "know" about the abstract class (unless your main also does for polymorphism, which I don't think is in the scope of your assignment.

Also remember to have include guards.


What are guards?


I typed in 'c++ guards' into google. It brought me this link: en.wikipedia.org/wiki/Include_guard

not bad... not bad at all!


After 5 minutes of posting, I slapped myself for not googling it first and it lead me to that wiki. Definitely help me out.

EDIT: Nevermind. I was being stupid.
--

Anyways, I just wanted to say thank you to everyone who answered my questions and helped me with my problems. If it weren't for you guys, I'd have some weird anxiety attack.
Aiyeeeee
mcc
Profile Joined October 2010
Czech Republic4646 Posts
March 19 2013 06:04 GMT
#5452
On March 19 2013 09:19 Ilintar wrote:
I agree with you, however, note that I was explicitly speaking about userland stuff. All of the things you described are quite valid within kernel land (and mission-critical code such as eg. game engines) but not usually relevant in userland code.

As for the drivers, you might be right, I did underestimate the embedded market.

Regarding debugging C code vs C++ code - sorry for using a mental shortcut, I meant not just the debugging process per se, but the entire bugfixing process. It's a simple matter of the compiler simply not informing you that you wanted to cast the foo_t pointer to bar_t, not to baz_t (and baz_t is very similar to bar_t, but lacks a single function pointer at the end that is only used in very specific situations). Any time you have to rely on the programmer's know how instead of the typing system, you are bound to spend more time fixing bugs. After all, that's the main reason low-level languages like C were pretty much abandoned in userland in the first place.

Finally, I also don't want to revisit Language A vs Language B wars and I fully agree that one must pick the right language for the job. What I'm simply saying that, unless your job involves very fine-tuned optimizations, for OOP applications C++ beats C. The fact that it's possible to hack OOP related stuff into C doesn't mean that C is as well suited natively for OOP programming as is C++ (or Java, or Ocaml, or any object-oriented language).

Well if you define userland as you do then C++ has also no business of being language of choice as all the arguments that you pointed at C can be pointed at C++ and you reach a conclusion that C#(/Java/D/..) should be used in userland.
Kambing
Profile Joined May 2010
United States1176 Posts
March 19 2013 08:15 GMT
#5453
On March 19 2013 12:52 Release wrote:
Hi. Current junior in high school and am thinking about a future in programming.

Which majors/colleges should I be looking into?
+ Show Spoiler +

I know that CMU/MIT/Standford are the three of the best but what are some others?


Computer science is the clear route to go if you are interested in a job as a programmer. Note that computer science is not programming, however, so be ready to take on a major that encompasses both programming as well as mathematical reasoning.

As for which colleges to look at, you can look at ranking lists such as U.S. News:

http://www.usnews.com/education/worlds-best-universities-rankings/best-universities-computer-science

Frankly, though, ranking lists like these are focused on performance in-discipline as a function of research output and not necessarily quality of undergraduate education. While most of these universities will offer excellent computer science programs, you should also look at liberal arts colleges, e.g.,

http://colleges.usnews.rankingsandreviews.com/best-colleges/rankings/national-liberal-arts-colleges

as they can offer an equal, if not superior, undergraduate experience than a research university.
heishe
Profile Blog Joined June 2009
Germany2284 Posts
Last Edited: 2013-03-19 10:29:06
March 19 2013 10:14 GMT
#5454
On March 19 2013 09:05 RoyGBiv_13 wrote:
Show nested quote +
On March 19 2013 07:37 Ilintar wrote:
On March 19 2013 05:36 CecilSunkure wrote:
On March 19 2013 05:26 Ilintar wrote:
Agreed - coding OOP in C is like coding lambda abstractions in Java - might be fun or useful as an exercise, but in both cases there are simply languages better suited for the job.

OOP in C was actually the language of choice for a lot of GBA games. But again the point isn't to learn it professionally, but just to have a solid understanding of how what you're using in C++ works. Using function pointers and typecasting in C for OOP isn't as difficult or tedious as you guys seem to think it is.

On a different topic, if I could I'd code everything in C instead of C++. I really like C. It's just that templating in C++ is so useful, and there are some very nice C++11 features coming around. Whenever someone codes something in C it's almost always completely obvious as to what they are trying to do. With C++ though there are a lot of ways to hide a lot of things. Auto-generated code, things can be run in non-intuitive ways. It's a big problem when a poor C++ programmer is writing code within a team. Of course the solution isn't "lets all code in C", it's just to use C++ appropriately. Even at my school though it's hard to find solid programmers to work with. I can't imagine how hard it would be to find a fit for a team that works primarily with C++ out in the world. Perhaps if more people started "hitting the ground running" in C things would be different?


The problem is, miniscule optimization gains that you get by coding stuff in C over C++ (miniscule because both langauges are compiled, native languages, so the code will compile to basically the same assembly with a proper compiler, minus vtables and OOP-specific stuff, plus the C++ compiler can optimize a lot of OOP code that the C compiler cannot) is lost by programmer hours. C++ has type-checking for all sorts of OOP stuff that C does not - by definition, if you typecast pointers, you are basically telling the compiler "I know what I'm doing, I told you before that this was stuff of type Foo, but it's really stuff of type Bar". So the compiler will basically tell you "okay, but don't complain later when you get a segfault since you reference a non-existing function poiner". The issue here is, pointer arithmetic is notoriously hard to debug and takes away tons of valuable programmer time. Agreed - there are times when you need to do OOP-style programming in C and Linux kernel drivers are a fine example, but then again, most people don't program Linux kernel drivers. In normal, user-land applications, there is really not reason nowadays to use C over C++ if you want to do OOP.


I really don't want to get back into this age-old Language A vs Language B argument, so let's just say that each has their benefits and drawbacks, and a good programmer should be able to choose the best language to fit the problem.

What actually is worth discussing is the implementation specific differences between C and C++, and why you would use one over the other. Please don't take this as an assault at you, or at C++, I am just trying to clear up a few misconceptions before others read them and take them for truth.

Misconception A: C++ is as fast as C, because they are both static typed compiled languages
+ Show Spoiler +
Currently, there is a phenomenon known as the "C++ tax", which is, in effect, the overhead in using C++ over C to implement a data structure or algorithm. It isn't much, but it's there, and in plenty of applications, that is enough to warrant using C. Simple examples will compile to roughly the same assembly, but if you use templates or make excessive use of inheritance, then the overhead of C++ goes through the roof. You'll note that those are two of the biggest "advantages" C++ has to C as far as OOP goes. They are also the biggest performance drawbacks.

I have benchmark data from my company's compiler running Adobe's C++ Test Suite to support this. We recently reduced this tax by a large factor with recent optimizations, but for real-world cases, the C++ tax is still very real.

I wont release the specific numbers, but here are two commonly used sorting algorithms that were 3x faster in C until recently.

Vector Sort A 2.9 – 3.0x
Vector Sort B 1.6 – 1.8x


Misconception B: Pointer logic makes OOP in C harder to debug
+ Show Spoiler +

"Pointer magic", as I like to call it, is the method of using pointers to functions, and applying those functions later. When doing this, you end up seeing really crazy function calls which are hard to revoke and end up causing confusion because you aren't even sure which function is being called. So, in effect, C is harder to read than C++.

But is it harder to debug?
+ Show Spoiler +
No, duh.

The tools behind developing for C have been advancing at a breakneck speed for decades now. There is capability in debuggers to step through this sort of program design, and tell you which function it's expecting to be there, then step into that function, knowing the values of everything passed through, etc.. We have an effective technological way to "read" our way through a C program rather well. C++ too, but it benefits less because of this, because in C++, the problem is not that the code isn't readable, the problem is that C++ code can lie through its teeth at you without the debugger picking it up.

Well, C++ is more readable, especially when it comes to OOP, but with modern tools, C is pretty debuggable as well. What it really comes down to is the time it takes to identify, fix, and test after identifying a bug. The old adage that C++ gives you enough rope to shoot your whole leg off or something is dead-on. I only have anecdotal evidence, but it usually takes 3-4 times as long to identify a bug in C++ as it does in C. It takes less time to fix in C as well, because compile times are usually only a fraction of the time for the same size program, and generating a test is also quicker. Effectively, the maintenance cycle for C is much tighter, and thus, easier to work with.


Misconception C: No one writes Linux kernel drivers
+ Show Spoiler +
The embedded market is enormous. There are way more microchips in this world than there are PC's. Even with the choice of using C++ in an embedded system, most developers opt for using C because its faster to write a program to do what you want, easier to debug when it doesn't do what you want, and faster running as well. It also takes less space and thus can be ran on cheaper microchips.

I won't go on to where the OOP feature of C can be seen on other platforms, but you can imagine that its not isolated into just one market. C is pervasive everywhere.


With that being said, I wouldn't dream of writing something like a game in C, because that isn't what it is good at. Still probably wouldn't use C++, but that is personal preference, and nothing against the language.

Source: I am an support engineer at an compiler company


Misconception A is wrong. First of all, templates don't have any runtime overhead. It's literally zero, since templates are completely resolved at compile time.

Second, the inheritance overhead you speak of exclusively comes from virtual methods/functions. You'd be very hard pressed to show me a real world application where the overhead from virtual methods is actually measurable. In only an incredibly small application set you will actually see that suck up enough performance that it's actually noticeable (more than 0.01% of program performance taken up). You can pretty much only notice it when you have a ton of virtual methods being called in very tight loops an incredibly large amount of times relative to all other things that are going on. This almost never happens. I've been professionally active in coding high-performance code, and I can tell you with confidence that inheritance overhead is the one thing that people who don't know what they're talking about when it comes to speed optimization end up way overestimating (it usually doesn't measurably exist at all).

And that isn't even mentioning the fact that this isn't an inherent disadvantage of C++ at all. Virtual functions are the result of an architectural design decision, and if you were to implement the same architecture in C OOP, C would have the same amount of overhead.

Misconception B: Two things make no sense here: First of all, readability of code absolutely impacts debugging performance (the time of man hours you have to invest in order to find a bug). I don't know how that isn't obvious to you, so saying C OOP isn't harder to debug is a simple fallacy. Second, I'd like you to give some examples of C++ "lying through it's teeth" without debuggers picking it up, because it heavily sounds like you haven't used a decent C++ debugger ever or don't have much experience with C++ at all.

Misconception C:
Your point actually shows a great misconception that people have over the embedded community, that C is used over C++ because the used microprocessors are supposedly slow as fuck and somehow C is faster or more memory efficient than C++ to such a degree that most people prefer C. Yet the real reasons are two fold: Historical reasons, and safety reasons.

Historical reasons because there have naturally been more C programmers in the embedded community so when you start out in that community in a company, or even just as a hobby programmer, you will get a barrage of people telling you that C is better for it without knowing what they're talking about. Just like in the game development community, you will have most people suggest C++ to you over something easier to use like C# or Java even if you explicitly tell them you're targeting the PC indie market, because they don't know what they're talking about. C is simply the tool that all the bosses and partners you work with when you start out are by far the most comfortable with, so naturally the field will be filled with C programmers. It's the same in the mainframe community, where everyone still programs COBOL and all "seasoned, experienced" engineers in that field will tell you that it's the best language for the job even though that language is so terribly outdated and lacking a lot of features it isn't even funny, because the average programmer age in that community is over 50. I'm not even kidding with that average over 50.

As a bonus: I've talked to two people who've been active in that field for long years (in big companies, one in a research institute and one as head engineer for a big car manufacturer), and they both tell me that pretty much everyone with any sense at all is now migrating to C++ for new embedded projects for several reasons (like used development processes, most students coming out of universities only know Java, etc.) and suddenly the supposed performance and memory benefits that C is supposed to have aren't a problem anymore at all! Of course this change is happening extremely slowly (after all, most big companies still use the waterfall development process) and will take a long while (probably >50 years) to complete.

Safety reasons: Due to things like RAII, inheritance, exceptions and that whole C++ stuff, it can be hard (especially for bad engineers) to make confident statements (as in: get very high test coverage of all possible test cases with a high certainty) about a piece of software that is written in C++, over something that is written in C. This however is an absolutely huge requirement in many of the really big companies that program embedded stuff in the safety sector. Just think about any field where peoples health depends on the correct functioning of a program. So that's why they use C there.
If you value your soul, never look into the eye of a horse. Your soul will forever be lost in the void of the horse.
Ilintar
Profile Joined October 2002
Poland794 Posts
March 19 2013 11:24 GMT
#5455
On March 19 2013 15:04 mcc wrote:
Well if you define userland as you do then C++ has also no business of being language of choice as all the arguments that you pointed at C can be pointed at C++ and you reach a conclusion that C#(/Java/D/..) should be used in userland.


And it's indeed so - C++ as a programming language has been slowly losing ground to the combo of Java/C#.

There's still one reason for using C++, namely that it compiles to native code and doesn't run on a virtual machine - that is still relevant eg. for the gaming industry, although increasingly less so (a lot of people nowadays code eg. with the Unity framework, where you can even write your logic in JavaScript).
Former webmaster @ WGTour.com / BWLauncher developer
obesechicken13
Profile Blog Joined July 2008
United States10467 Posts
Last Edited: 2013-03-19 17:51:25
March 19 2013 13:34 GMT
#5456
On March 19 2013 12:52 Release wrote:
Hi. Current junior in high school and am thinking about a future in programming.

Which majors/colleges should I be looking into?
+ Show Spoiler +

I know that CMU/MIT/Standford are the three of the best but what are some others?

Most computer engineering and computer science majors in big name universities teach a lot of unnecessary courses. You don't need to build an operating system or compiler or build gates or use gaussian distributions or draw circuit diagrams etc...

You'll learn about the things we talk about eg. inheritance and type comparisons as well as value comparisons in any intro to computer programming class at any school. I can't say anything about the quality of other schools as I have not been to other schools. I do think that a degree at a well known school like the three you listed is worth more than one at a lesser known one though (to employers) and that first job sets you on a good path for the future.
I think in our modern age technology has evolved to become more addictive. The things that don't give us pleasure aren't used as much. Work was never meant to be fun, but doing it makes us happier in the long run.
ShoCkeyy
Profile Blog Joined July 2008
7815 Posts
Last Edited: 2013-03-19 17:44:10
March 19 2013 17:43 GMT
#5457

<?php

$data = array(
'Select a State'=>"Select a State",
'AL'=>"Alabama",
'AK'=>"Alaska"
);

$selected = $_POST['state'];
?>


<div class="input">
<form action="in-test.php?state=<? echo http_build_query($data, '', '&amp;'); ?>" method="post" onSubmit="return validateForm()" name="myform">
<div class="select">
<select name="state" id="state" class="uni">
<?php
foreach ( $data as $value=>$text ) {
if ( intval($selected) == intval($value) ) {
echo '<option value="'.$value.'" selected="yes">'.$text.'</option>'."\n";
} else {
echo '<option value="'.$value.'">'.$text.'</option>'."\n";
}
}
?>
</select>
</div>
<div class="btn_area">
<input name="getstarted" type="submit" class="input_btns" value="">
</div>


</form>
</div>


I need to be able to pull the state value into the URL with out using GET. Any clue on what syntax I should be using? - _ -; Been stuck on this for a while, right now it's giving me only the first array as AL=Alabama. I need it to be just the value (AL)... Reason I can't use method="get" is because of how the system we post into is set to HTTP POST and I can't change it.
Life?
tofucake
Profile Blog Joined October 2009
Hyrule19173 Posts
March 19 2013 17:48 GMT
#5458
I don't understand your question. You don't pull data into something, you pull it out.
Liquipediaasante sana squash banana
ShoCkeyy
Profile Blog Joined July 2008
7815 Posts
March 19 2013 17:52 GMT
#5459
I just need to get the value of the state selection depending on what the user picked into the URL with out using $_GET. So it passes to the next page. The syntax I am using right now in the action="" gets only the first array value and it returns it as AL=Alabama. I need just AL to be returned and the value of what the user selected.
Life?
tofucake
Profile Blog Joined October 2009
Hyrule19173 Posts
March 19 2013 18:02 GMT
#5460
Action is the submit. Remove it.
Liquipediaasante sana squash banana
Prev 1 271 272 273 274 275 1032 Next
Please log in or register to reply.
Live Events Refresh
OSC
16:00
OSC Elite Rising Star #17
Nicoract vs MixuLIVE!
Babymarine vs MindelVK
ForJumy vs TBD
Shameless vs Percival
SteadfastSC132
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
mouzHeroMarine 664
Lowko470
SteadfastSC 132
ProTech126
MindelVK 34
Codebar 28
StarCraft: Brood War
Britney 21637
Calm 3107
Shuttle 735
GuemChi 550
EffOrt 503
Larva 314
Rush 210
firebathero 159
BeSt 132
Dewaltoss 95
[ Show more ]
PianO 67
yabsab 27
Aegong 19
soO 18
Sacsri 17
scan(afreeca) 12
SilentControl 10
Terrorterran 10
HiyA 10
NaDa 6
JulyZerg 6
Dota 2
Gorgc6718
Dendi949
420jenkins334
XcaliburYe175
Counter-Strike
fl0m4235
zeus304
chrisJcsgo40
minikerr13
Heroes of the Storm
Khaldor148
Other Games
Grubby3580
ArmadaUGS105
Livibee92
Mew2King80
QueenE51
KnowMe50
Trikslyr49
Organizations
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 16 non-featured ]
StarCraft 2
• poizon28 19
• Reevou 8
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• FirePhoenix0
• STPLYoutube
• ZZZeroYoutube
Dota 2
• C_a_k_e 2653
• WagamamaTV579
Other Games
• Shiphtur129
Upcoming Events
Replay Cast
6h 29m
Korean StarCraft League
1d 9h
CranKy Ducklings
1d 16h
WardiTV 2025
1d 18h
SC Evo League
1d 18h
BSL 21
2 days
Sziky vs OyAji
Gypsy vs eOnzErG
OSC
2 days
Solar vs Creator
ByuN vs Gerald
Percival vs Babymarine
Moja vs Krystianer
EnDerr vs ForJumy
sebesdes vs Nicoract
Sparkling Tuna Cup
2 days
WardiTV 2025
2 days
OSC
2 days
[ Show More ]
BSL 21
3 days
Bonyth vs StRyKeR
Tarson vs Dandy
Replay Cast
3 days
Wardi Open
3 days
StarCraft2.fi
3 days
Monday Night Weeklies
3 days
Replay Cast
4 days
WardiTV 2025
4 days
StarCraft2.fi
4 days
PiGosaur Monday
5 days
StarCraft2.fi
5 days
Tenacious Turtle Tussle
6 days
The PondCast
6 days
WardiTV 2025
6 days
StarCraft2.fi
6 days
Liquipedia Results

Completed

Proleague 2025-11-30
RSL Revival: Season 3
Light HT

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
YSL S2
BSL Season 21
CSCL: Masked Kings S3
Slon Tour Season 2
Acropolis #4 - TS3
META Madness #9
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
Kuram Kup
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.