3 ms·
After using python and C++ in production for more than 10 years I'll reach for python for trivial things, but for something complex give my C++ over python! Ye
by bluGill 5y ago
After using python and C++ in production for more than 10 years I'll reach for python for trivial things, but for something complex give my C++ over python! Yes C++ has awful syntax full of footguns, but at least I can change a large project. At 50k lines of code python becomes something you can't change for fear of some 1 in a million path that will only break after it hits production. Static types means that C++ won't compile in most of those cases. As a result python needs a lot more unit tests, and even 100% code coverage isn't assurance that you covered all the cases that can crash.
Don't take the above as a statement that C++ is a great language. I'm interested in rust and ADA (just to name a few that keep coming up) which might or might not be better for my needs. I'm a C++ expert though, so I know what the limits are.
- formerly_proven 5y agoI too have C++ experience and would never take "it compiles" as a sign that it'll work. I don't dispute that there are languages which have sufficiently powerful and complex type systems and compilers that enable you to model significant amounts of domain constraints such that you feel you don't "need" tests, because it'll probably work if it compiles (though I'd argue that you really ought to still have tests to verify your modelling of the domain in the type system is correct, i.e. a set of programs that must typecheck and a set of programs that mustn't typecheck) -- C++ is not usually one of those.
- bluGill 5y agoTrue. I have more confidence my c++ works with 50% code coverage in tests than python with 100% coverage. I try to model my domain in C++'s types. it isn't easy, but even avoiding int and bool helps a lot to ensure my code doesn't make stupid mistakes. Haskell would give me more power, but I'm moving my C++ in that direction.
- hasmolo 5y agoi think your expertise in C++ might be affecting your view of python more than expected. i used to feel this way about languages other than my « primary » one and it turned out i just wasn’t as good at others and blamed the language for it
- ericbarrett 5y agoI agree with bluGill and I've done most of my career programming backend infra in Python. Give me C++, Rust, Go, Java, C#, TypeScript—as long as it has a type system. Eliminates a whole class of runtime errors and just makes life easier. When I'm dealing with large projects that have lots of moving parts and other developers, strict types are essential. It's true that one can write unit tests to firm up dynamically-typed code, but doing so is not only a slog, it makes changes more fragile and deployments a lot scarier. If you aren't perfect the first time you write the tests, instead of a build failing you get restart loops, dead threads, and in the worst cases data corruption from improper silent type coercion.
- bluGill 5y agoI have enough experience in python to know where the limits are. I've done more C++ for sure, but I have done a fair amount of python. I still reach for python for small projects where I'm not expecting over 10k lines of code.
- bjarneh 5y ago> C++ has awful syntax full of footguns HN never stops delivering new funny insults about this language :-)
- stackedinserter 5y agoPython in a project == tech debt. Same for bash scripts. For us, Golang turned out to be the optimal balance between (probably imaginary) strictness of C++ and "everything allowed until 2AM PD call" philosophy of Python. Even for simpler things like scripts and little auxiliary services Python is bad, because these little things tend to grow and get more complex.