Questions about C++, a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language.

learn more… | top users | synonyms

201
votes
43answers
14k views

My Dad is impatient with the pace of my learning to program. What do I do? [closed]

So my Dad bought me 5 books on programming (C++, Java, PHP, Javascript, Android) about a month ago. He's an architect and he knows NOTHING about programming. He bought me them because I told him ...
136
votes
15answers
63k views

When to use C over C++, and C++ over C?

I've been introduced to Computer Science for a little over a year now, and from my experience it seems that C and C++ are both considered to be "ultrafast" languages, whereas others such as Python and ...
106
votes
19answers
65k views

Is there any reason to use C++ instead of C, Perl, Python, etc.? [closed]

As a Linux (server side) developer, I don't know where and why should I use C++. When I'm going to performance, the first and last choice is C. When "performance" isn't the main issue, programming ...
80
votes
13answers
7k views

Way in over my head! (Dealing with better programmers)

I've just been hired as a member of a group that is developing in C++. For the last 11 years, I'd been coding on and off at my last job (some C, some Fortran, some C++). The coding I'd done was ...
79
votes
11answers
19k views

What backs up the claim that C++ can be faster than a JVM or CLR with JIT? [closed]

A reoccurring theme on SE I've noticed in many questions is the ongoing argument that C++ is faster and/or more efficient than higher level languages like Java. The counter-argument is that modern JVM ...
78
votes
15answers
7k views

Why did memory-managed languages like Java, Javascript, and C# retain the `new` keyword?

The new keyword in languages like Java, Javascript, and C# creates a new instance of a class. This syntax seems to have been inherited from C++, where new is used specifically to allocate a new ...
74
votes
14answers
25k views

Why are most browsers developed in C++ [closed]

It seems like most of common web browsers (Firefox, Chrome, Safari) are developed using C++. My question is straightforward. Why they use mainly C++ rather than any other language? Edit: What ...
72
votes
12answers
7k views

Does auto make C++ code harder to understand?

I saw a conference by Herb Sutter where he encourages every C++ programmer to use auto. I had to read C# code some time ago where var was extensively used and the code was very hard to ...
69
votes
19answers
5k views

Is it ok to replace optimized code with readable code?

Sometimes you run into a situation where you have to extend/improve some existing code. You see that the old code is very lean, but it's also difficult to extend, and takes time to read. Is it a good ...
64
votes
16answers
11k views

Do I really need oop for my kind of job? After 10 years I think I don't [closed]

After 10 years of writing something like business logic for my company I realized that for 95% of my code I just don't need any special OO techniques. For years I tried to get better with all that OO ...
62
votes
7answers
6k views

Why declare a variable in one line, and assign to it in the next?

(I figured this question was already asked, and searched for it, but was unable to find a duplicate; if I missed something, please delete this one and accept my apologies!) I often see in C and C++ ...
62
votes
8answers
36k views

Is modern C++ replacing C#? Is Microsoft pushing developers to adopt C++? [closed]

I hear about modern C++ popularity and some talks about migrating back to C++ from C# or other C-like languages. I know about C++11 features but I would like to hear your experiences, especially from ...
56
votes
3answers
8k views

Is C++11 Uniform Initialization a replacement for the old style syntax?

I understand that C++11's uniform initialization solves some syntactical ambiguity in the language, but in a lot of Bjarne Stroustrup's presentations (particularly those during the GoingNative 2012 ...
54
votes
16answers
2k views

Why should I care about micro performance and efficency?

Many questions and answers on the C/C++ pages, specifically or indirectly discuss micro performance issues (such is the overhead of an indirect vs direct vs inline function), or using an O(N2) vs ...
53
votes
14answers
8k views

Why would it ever be possible for Java to be faster than C++?

Sometimes Java outperforms C++ in benchmarks. Of course, sometimes C++ outperforms. See the following links: http://keithlea.com/javabench/ ...
53
votes
17answers
5k views

What programming problems are best solved by using pointers?

Well, I basically understand how to use pointers, but not how best to use them in order to do better programming. What are good projects or problems to resolve involving the use of pointers so I can ...
53
votes
11answers
8k views

A modern review of Java [closed]

I've been programming for a few years and I began in Java, and in my time I've found many different sources claiming Java to be an inferior language in some way or another. I'm well aware that each ...
50
votes
11answers
2k views

Why do we have postfix increment?

Disclaimer: I know perfectly well the semantics of prefix and postfix increment. So please don't explain to me how they work. Reading questions on stack overflow, I cannot help but notice that ...
48
votes
12answers
3k views

Is it reasonable to null guard every single dereferenced pointer?

At a new job, I've been getting flagged in code reviews for code like this: PowerManager::PowerManager(IMsgSender* msgSender) : msgSender_(msgSender) { } void PowerManager::SignalShutdown() { ...
48
votes
12answers
5k views

Did the developers of Java consciously abandon RAII?

As a long-time C# programmer, I have recently come to learn more about the advantages of Resource Acquisition Is Initialization (RAII). In particular, I have discovered that the C# idiom: using (var ...
44
votes
16answers
5k views

Languages on a resume: Is it better to put “C/C++” or “C, C++”?

I'm graduating in a couple of weeks, and my resume (as expected) lists the languages that I've had experience with. Previously I've put "C/C++", however back then I didn't have that much experience ...
44
votes
11answers
3k views

What can I do when the interviewer doesn't know the answer to his/her own question? [closed]

Yesterday I had a terrible experience in an interview. Interviewer asked me about pure virtual function. I said, It may or may not have definition in base class, but derived classes should provide ...
44
votes
11answers
42k views

For what reasons should I choose C# over Java and C++?

C# seems to be popular these days. I heard that syntactically it is almost the same as Java. Java and C++ have existed for a longer time. For what reasons should I choose C# over Java and C++?
44
votes
16answers
3k views

Strictness in programming methods among Stack Overflow users [closed]

I've been a member of Stack Overflow for a couple of weeks now and have answered questions and read others answers, mostly in C/C++. True, I have learned about some things. For example, undefined ...
44
votes
16answers
13k views

Extremely trivial C++ phone interview question [closed]

My company is currently interviewing for a developer position, and a disturbingly high number of candidates with good resumes end up being total frauds. We do have a written technical test which works ...
43
votes
12answers
2k views

Philosophy behind Undefined Behavior

C\C++ specifications leave out a large number of behaviors open for compilers to implement in their own way. There are a number of questions that always keep getting asked here about the same and we ...
42
votes
6answers
7k views

Is `catch(…) { throw; }` a bad practice?

While I agree that catching ... without rethrowing is indeed wrong, I however believe that using constructs like this: try { // Stuff } catch (...) { // Some cleanup throw; } Is acceptable in ...
42
votes
8answers
5k views

Why are there so many string classes in the face of std::string?

It seems to me that many bigger C++ libraries end up creating their own string type. In the client code you either have to use the one from the library (QString, CString, fbstring etc., I'm sure ...
42
votes
13answers
8k views

How to find a programming mentor? [closed]

I decided to learn programming. I've been reading SO for few days, and I think I will start with C++, as I read some articles. I am aware of loops, arrays, program logic and objects a little and I ...
42
votes
4answers
19k views

When do you use float and when do you use double

Frequently in my programming experience I need to make a decision whether I should use float or double for my real numbers. Sometimes I go for float, sometimes I go for double, but really this feels ...
41
votes
10answers
4k views

Is better Show() + Hide() or SetVisible(bool visible)?

What is better and why? (From interface-design point of view) : a) To have two Show() and Hide() functions b) To have one SetVisible(bool visible) function EDIT: For example some object have ...
39
votes
12answers
2k views

Which C# practices should be avoided in C++?

I'm currently teaching myself C++. I'm very proficient at C#, and was wondering which common practices in C# can lead to difficulties in C++, and what a C++ programmer should do instead.
39
votes
5answers
23k views

What is the role of C++ today?

Currently I'm an IT student and I'm wondering what is still important in C++ today, what for is it used? I completed basic C++ course in my university but I can't imagine where can I use my knowledge ...
39
votes
12answers
12k views

What's the benefit of object-oriented programming over procedural programming?

I'm trying to understand the difference between procedural languages like C and object-oriented languages like C++. I've never used C++, but I've been discussing with my friends on how to ...
39
votes
8answers
3k views

Can modern OO languages compete with C++'s array store performance?

I just noticed that every modern OO programming language that I am at least somewhat familiar with (which is basically just Java, C# and D) allows covariant arrays. That is, a string array is an ...
38
votes
3answers
9k views

Can somebody explain me what are lambda things in programming?

So far I heard about : Lambda calculus Lambda programming Lambda expressions Lambda functions Which all seems to be related to functional programming... Apparently it will be integrated into ...
36
votes
6answers
5k views

Good example of complex code using TDD [closed]

What would be a good example of the use of TDD in large, real-life, complex, projects? All the examples I've seen so far are toy projects for the purpose of a book or a paper... Can you name an ...
35
votes
15answers
10k views

If you need more than 3 levels of indentation, you're screwed?

Per the Linux kernel coding style document: The answer to that is that if you need more than 3 levels of indentation, you're screwed anyway, and should fix your program. What can I deduce ...
35
votes
7answers
2k views

C++ Interview question

This problem was given to me on previous job interview test. It is over now, but I would like to go through my mistakes and hopefully be more prepared next time! // Identify as many bugs and ...
35
votes
7answers
1k views

How do people know the C++ Standard so well?

First of all, this is not a formal C++ question. I have been working with C++ for many years. Most of time, I improve my skill by working on different projects, reading good books, and learning from ...
34
votes
8answers
3k views

In C++, how much programmer time is spent doing memory management

People who are used to garbage collected languages are often scared of C++'s memory management. There are tools, like auto_ptr and shared_ptr which will handle many of the memory management tasks for ...
32
votes
17answers
5k views

Teaching C++ to first time high school students: Where to draw the line?

I will be mentoring a team of high school students for the FIRST Robotics Competition, most teams here develop[ their robot software using C++. For many of the students on the team this will be their ...
32
votes
4answers
5k views

How to make the switch to C++11?

I've been programming in C++ for a while now, but mostly things centered around the low-level features of C++. By that I mean mostly working with pointers and raw arrays. I think this behavior is ...
31
votes
7answers
4k views

What did Bjarne Stroustrup mean by his characterization of C and C++?

There's a quotation by Bjarne Stroustrup that says: C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg. I've often come across this ...
31
votes
10answers
2k views

Difference between Idiom and Design Pattern?

What is the difference between idiom and design-pattern? It seems that these terminologies overlap somewhere; where exactly, I don't know. Are they interchangeable? When should I use what? Here is a ...
31
votes
6answers
4k views

Why are there no package management systems for C and C++? [closed]

There are some programming languages for which exist their own package management systems: CTAN for TeX CPAN for Perl Pip & Eggs for Python Maven for Java cabal for Haskell Gems for Ruby Is ...
30
votes
20answers
4k views

C++ areas you look for during interview

If you are taking an interview of an candidate without any prior work experience and want to find out how good he/she is in C++ what are the areas you generally look for ?
30
votes
17answers
6k views

How can I feel more confident about my programming skills? [closed]

Programming isn't alien to me. I first starting doing markup (HTML, now please don't laugh at me) when I was 12 and a little bit of BASIC when I was 13 (I knew much about Flowcharts, Pseudocodes at ...
30
votes
2answers
2k views

Why are reference-counting smart pointers so popular?

As I can see, smart pointers are used extensively in many real-world C++ projects. Though some kind of smart pointers are obviously beneficial to support RAII and ownership transfers, there is also a ...
29
votes
6answers
10k views

Why does Facebook convert PHP code to C++?

I read that Facebook started out in PHP, and then to gain speed, they now compile PHP as C++ code. If that's the case why don't they: Just program in c++? Surely there must be SOME errors/bugs when ...