Live data from Hacker News

Does C++ still deserve a bad rap?

nibblestew.blogspot.com

241–250 of 310 posts

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

#241
I been programming Java for around 10 years. I tried multiple times to switch to C++. But tooling is turn off. May be I am spoiled by Java.

What I want is easy build and dependency management system like maven.

I wish few professional C++ dev unite and build an open source tool like maven (assuming it will not take lot of time) which allow me to:

1. Create a project from skeleton project 2. compile 3. test 4. build/run 5. Key=value=version type system to download and auto build dependency.

That's it. :)

I tried building myself, but I think it is too much for a beginner project. I named the project 'goat'.

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

#242
post #216

Modern C++ can be a joy to write, and is fine for a lot of tasks. It's hard to beat the combination of performance characteristics and higher-level constructs. The issue with C++ is that it's unsafe by default. Foot-guns abound. The right way is to make everything safe by default and provide an escape hatch when needed, e.g. Rust's unsafe or C#'s unmanaged. Unfortunately, there's no way to "fix" C++ to be safe-by-def…

I wonder would a compile time switch that enbales 'safe by default' be an option. At least then it means programs could transition to becoming fully able to compile in this safe mode and only let subsets (e.g. certain files in a project or old libraries) use the unsafe by default mode. It would be less of a sharp shock and could allow people time to transition, and know where to spend efforts to become safer.

One thing we do in the Firefox codebase is build using a clang plugin that we wrote to statically enforce additional rules.

It’s not a perfect solution , and obviously not built in, but it is a big help for avoiding footguns.

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

#243
post #189

Earlier quoted context omitted.

Hard agree. I was enthusiastic about reading that book when I got it, as I'd been very late to the bandwagon of new C++11 and C++14 features. Ended the book in a pessimistic tone. It looked more like a cookbook of pitfalls _everywhere_. Every new feature looked exciting, but came with a list of cases where the language decides to leave you on your own when it gets too uncomfortable (the "well that's undefined behavio…

I think in Scott Meyers case it is he basically never used C++ in production, which in some sense is ok, since he makes his living as a language expert, but sometimes this shines through; also from a D conference talk I remember, even he got sick of it and switched to D. Also let me use this comment to recommand John Lakos, his talks, his books. He knows how to build large scale applications and if you saw his talk o…

Thanks for the recommendation, I'll have a look at his work, for sure.

Also I'd be curious to see that talk you mention, do you remember anything about it that could help in searching for it?

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

#244

Earlier quoted context omitted.

Python developer here just switched jobs to one that does C++. Let me warn you right now. It's not worth it. At all. Don't go down this path. Memory management is easy, but that's not the only crap you have to deal with. Templating and the whole C++ ecosystem with Cmake compiling to make is a giant headache. It takes about a week to integrate a new C++ library in source code and people are worried about installing or…

So how do you deploy your python app to your customers?

You deploy to the cloud. The customer downloads a web page and that functions as a client that communicates with the python server. Just like how most programming is nowadays.

But if you want a customer to download an app, which is much more rare nowadays than you can do what Eve online does or iron mail. They deliver actual client side python apps. I don't know what they use internally or how they did it, but pyinstaller is one option you can use to build a python executable.

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

#245
post #243

Earlier quoted context omitted.

I think in Scott Meyers case it is he basically never used C++ in production, which in some sense is ok, since he makes his living as a language expert, but sometimes this shines through; also from a D conference talk I remember, even he got sick of it and switched to D. Also let me use this comment to recommand John Lakos, his talks, his books. He knows how to build large scale applications and if you saw his talk o…

Thanks for the recommendation, I'll have a look at his work, for sure. Also I'd be curious to see that talk you mention, do you remember anything about it that could help in searching for it?

I think same talk but different recording: https://www.youtube.com/watch?v=MZUJsCh1wOY I think around 1:08:30 onwards (maybe even before) the example I had in mind.

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

#246

Earlier quoted context omitted.

I wonder would a compile time switch that enbales 'safe by default' be an option. At least then it means programs could transition to becoming fully able to compile in this safe mode and only let subsets (e.g. certain files in a project or old libraries) use the unsafe by default mode. It would be less of a sharp shock and could allow people time to transition, and know where to spend efforts to become safer.

One thing we do in the Firefox codebase is build using a clang plugin that we wrote to statically enforce additional rules. It’s not a perfect solution , and obviously not built in, but it is a big help for avoiding footguns.

You can do a lot to make modern C++ programming safer with linters, clang-tidy, sanitizers, valgrind, etc. But it's a lot of work and a lot of compute to bolt that on top of a fundamentally unsafe language. It's out of reach for a lot of organizations and requires a substantial amount of organizational coding discipline.

It's like the old saw that gets trotted out about C and C++; you can write safe code in any language if you're disciplined about it. The point of safe languages is to make it easy and accessible to write safe code; to design into the language a "pit of success" rather than requiring a big slog to make a flawed language usable.

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

#247
post #201

Earlier quoted context omitted.

To be fair, C++'s standard I/O library is really bad. There is probably an almost universal consensus in the C++ world that the locale library is the worst standard library, immediately followed by iostreams. For small programs that's annoying, although using libc IO is usually fine for them. However, C++ is probably one of the top 3 languages for developing large applications (Java would also be there, not sure whic…

In terms of large projects C++’s role is very much shrinking. C++’s last major strength is being cross platform, but new platforms keep excluding it. You can’t program on iOS or client side websites with it. Microsoft actively discourages using C++ on Windows, and C# took over for large projects. Essentially C++ and the modern ideas about computer security are at war.

> Microsoft actively discourages using C++ on Windows,

Really? That's the opposite of my impression. It seems to me that they promote it as co-equal to C# as primary focus in their constellation of supported and encouraged application programming languages.

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

#249
post #188

The code for that blog post is fragile in an interesting way. Its safety and security depend on a subtle invariant: that the 'word_regex' does not match a string containing any non-ASCII character. If requirements changed so the regex could match a non-ASCII character, then one of the 'c' chars could have a negative value other than -1. https://en.cppreference.com/w/cpp/string/byte/tolower says "If the value of ch is…

In at least some locales tolower segfaults under that condition, in glibc at least.

(before anyone says that ‘in reality it’s probably fine’)

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

#250

Earlier quoted context omitted.

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…

> implementing the hard things on C or C++ This misses the point. I don't care how the language implements the functionality if it meets my performance requirements and it is convenient to use.

> This misses the point. I don't care how the language implements the functionality if it meets my performance requirements and it is convenient to use.

I dont think it does, because it meant you are working on a simple language that can only afford to be simple delegating the harder parts to other languages that took the effort to be designed to deal with everything.

The convenience is payed by someone else, and the language that pay for the hard stuff are the ones that are complex, because they need to work well with any sort of algorithms.

Post reply on HN