Live data from Hacker News

Does C++ still deserve a bad rap?

nibblestew.blogspot.com

11–20 of 310 posts

Re: Does C++ still deserve a bad rap?

#11
post #4

Earlier quoted context omitted.

Why would that be more difficult in C++?

Because it doesn't even exist as provided functionality; you have to code basic stuff like this yourself. See for example https://stackoverflow.com/a/14267455

It is possible with a regex iterator

  #include 
  #include 
  #include 

  int main()
  {
   std::string s = "Python*C++*Java";
  std::regex regex("\\*");

  std::vector out(std::sregex_token_iterator(s.begin(), s.end(), regex, -1), std::sregex_token_iterator());

  for (auto &s: out) {
    std::cout 

Re: Does C++ still deserve a bad rap?

#13
TLDR Yes.

I having been writing C++ extensively for research/work/etc the past 5 years. Compared with modern languages it completely deserves the bad rap.

C++ has come a long way, can you write cleaner code than you could 10 years ago? yes. Are there safer abstractions than there were? yes.

The amount of issues I have to deal with in C++ on a day to day basis which are just non-issues in Rust or Go, etc.

Without complaining too much dependency management and tooling are stuck in the stone age.

Every time I get to use Cargo going back to C++ is a nightmare, even Python which has pretty poor tooling around this is a million light years ahead.

Even simple things like having to carefully order headers or deal with obscure cross-platform incompatibility are mostly non-issues in newer languages and the baggage of C and C++ leads to a lot of unnecessary pain that doesn't provide low-level control or performance advantages.

Re: Does C++ still deserve a bad rap?

#14
Right at the beginning,

> This calls for regular expressions

Why? A regular expression is a whole new program, written in a whole new programming language (one used to program finite state machines, instead of Turing ones, but still). Why not just write a simple function to compare string suffix? Is you programming language (C++, in this case) so anaemic that you need a whole different language to do such basic operations?

This is what people who don't like C++ complain about, in addition to the language, the self-indulgent culture around it.

Re: Does C++ still deserve a bad rap?

#15
The current state of C++ is that of Madonna trying to stay relevant in the modern music world. You can have her rap, have her dab, or use autotune but she still won’t fit in as easily as a Billie Eilish.

I look at C++ and wish it had C#’s compile-time attributes, first-class reflection, mixins, a decent syntax for pure virtual functions, and a more logical pointer syntax (it’s illogical and you know it). However, they can’t give me those things without drastically breaking backwards compatibility. At that point it’s a new language.

I wish we could just develop a C++ 2 for greenfield projects and stop development of C++ where it’s at instead of Frankensteining more features onto it. I guess that’s what Nim and Rust are for.

Re: Does C++ still deserve a bad rap?

#17
Is this a nerd sniping thing? It has been a while since I've wrestled with Perl, but I suppose the recursive file search would keep it from being a one-liner. 4-5 "reasonable" lines maybe? Definitely less than 80 characters? I see I don't even have Perl installed on this machine, oh well.

Re: Does C++ still deserve a bad rap?

#18

C++ is a very poorly designed language. A lot of the work being done by the committees is fixing Stroustrup's mistakes. Consider horrors such as this. In the following statement what are foo and bar? int x = foo(2) + bar(3); Most people will say foo and bar are functions and that's a reasonable guess. Unless you are talking about C++. In C++ foo and bar could be functions but could also lots of other things. For exam…

This weird ambiguous syntax exists to allow among other things templates that take either primitive or class types. It makes primitive types usable as if they are classes with copy constructors.

That being said, it can certainly be ugly. A lot of the ugliness comes from trying to maintain itself as a mostly superset of C. Technically it no longer is strictly that, but most C code will compile fine in a C++ source file.

Re: Does C++ still deserve a bad rap?

#19
post #2

I say this with a lot of love for C++, and I think it has gotten much better, but just try splitting a string via another string as the delimiter...

Is there any language where string handling doesn't suck? (No script languages please, because they cheat by implementing the hard things on C or C++) From memory the less horrible experience i had was with Go, but there's help for the slices on the runtime which let the difficult parts hidden and also the batteries-included std library, which is one of the most well designed standard libraries out there. Buffer mana…

I think it's pretty nice in Scala. I don't know if "no virtual machines" was implied as part of the "no script languages" request, though.

  scala> "Mary had a little lamb. The lamb was in federal witness protection.".split("lamb") 
  res0: Array[String] = Array("Mary had a little ", ". The ", " was in federal witness protection.")

Re: Does C++ still deserve a bad rap?

#20
Like every programming language out there, C++ is a tool. And like every tool out there it has its uses.

There isn't any point of using C++ to count words in a text file. Any high-level language like Python will beat you to it. However, there's one thing you can do in C++ and not in Python or JavaScript or PHP: fully control the memory layout of your data.

While you don't need it in most of the cases, it becomes a killer feature when directly dealing with large amounts of data:

* Try implementing an on-disk hash table in Python and you're stuck manually packing ints and longs in an out of arrays. In C++ it could a simple template used with a memory-mapped file.

* Try doing anything non-trivial on a microcontroller with 32KB of RAM. You could theoretically use a higher-level language, but you will end up using >10x amount of RAM.

* Try designing an application-specific data structure in any other language. Let's say you have an ~8GB in-memory database that slowly adds records one-by-one and then invalidates them in chunks. A C++ implementation will rip anything else to shreds. You just won't get the same speed and memory efficiency.

What it means in practice, is that unless you have an existing project that uses C++ anyway, you want to partition it: do the memory-critical part in C++, and communicate to it from a higher-level language via a high-level interface. You will get performance where you need it and a peace of mind everywhere else.

Post reply on HN