News for hackers. Stuff that matters.
Re:Selecting a programming language can be a form of prematu... by rich_sasha on Monday November 15, 2021 @04:19AM (#29225392)
I used to work at a C++ for prod, Python for prototype place. Time and time again, a 1-2kloc Python prototype, the bulk of which was written in a week, would take months to translate to C++, at times longer than the whole process of research+prototype.

I think it was 2 things: one, it is genuinely harder to write a valid C++ program. The language imposes non-trivial constraints on the programmer, for better and worse, and you have to navigate them for the thing to even compile. But two, C++ invites pedantry. I heard endless discussions about "ooh, template meta-programming", "struct or class", "but is this idempotent", "you should be using move semantics", "why on earth is this a unique_ptr".

I'm not saying C++ is worse, or that its trade-offs are not worth it, but for sure, from my experience, translating an algorithm into code is done far more quickly in Python than in C++. YMMV

Ah and also, this was definitely not a question of deficient C++ coders. The hiring standards for C++ were so high we were always short of devs. Meanwhile, Python prototypes were usually written by part-time ex-academia Python dabblers.

Re:Selecting a programming language can be a form of prematu... by gpderetta on Monday November 15, 2021 @04:42AM (#29225543)
I think a large part of the difference is the prototype vs prod. I have written prototypes in C++ in a few weeks that still took months to go to production. It is just that production-ready code require significant more ceremony, more config files, more complex error handling, code reviews and of course feature creep.

I still agree that Python can be much more efficient to write than C++. I just wish it wasn't so unbearably slow.

Re:Selecting a programming language can be a form of prematu... by rich_sasha on Monday November 15, 2021 @05:14AM (#29225738)
I would mostly agree, though not entirely. Continuing with the anecdata, at times I had enough waiting and put my prototype into prod, with significant hardening. I can't say I always got it right, but usually 3-5 days of very focused poking made the thing at least reliably run at the desired cadence, with rare but loud and graceful failures. For sure though, there is a tax for doing it all "properly".

Even then though, I have the impression that Python just makes it easier to write it all more quickly. It just doesn't invite you (as much) down rabbit holes of doing things even more properly.

Re:Selecting a programming language can be a form of prematu... by professoretc on Monday November 15, 2021 @01:59PM (#29231148)
> But two, C++ invites pedantry. I heard endless discussions about "ooh, template meta-programming", "struct or class", "but is this idempotent", "you should be using move semantics", "why on earth is this a unique_ptr".

Interestingly, I've consistently had the opposite experience. In C++, when I ask, "how do I do X" there will be a few different options, but pretty much any of them will do. As long as you avoid things that are definitely UB, you're fine. In Python, I'll find endless religious arguments about which is the most "Pythonic" method. Whenever I try to just hack out Python code to just get things done, I always feel like I'm being judged, because usually the quick-and-dirty method is far from the most Pythonic.

Re:Selecting a programming language can be a form of prematu... by twobitshifter on Monday November 15, 2021 @04:22PM (#29232940)
I think it all depends on who does your code reviews. I agree with GP that c++ has religious adherents to the one-true-undocumented-in-their-head standard who will make writing it a nightmare. In python the philosophy is supposed to be - there is an obvious way to do things and that’s the right way. However this does fail from time to time.

Ruby on the other hand embraces many different syntaxes to do the same thing, but they’re all accepted as correct in the traditional view.

Re:Selecting a programming language can be a form of prematu... by kitd on Monday November 15, 2021 @10:29AM (#29228522)
But two, C++ invites pedantry. I heard endless discussions about "ooh, template meta-programming", "struct or class", "but is this idempotent", "you should be using move semantics", "why on earth is this a unique_ptr".

I wonder what the result would have been in eg. Go or Rust, where that level of conversation doesn't exist. True, others would have taken place instead, but at a higher level nearer the design, where they should have been happening anyway.

Re:Selecting a programming language can be a form of prematu... by munificent on Monday November 15, 2021 @01:40PM (#29230885)
> Time and time again, a 1-2kloc Python prototype, the bulk of which was written in a week, would take months to translate to C++, at times longer than the whole process of research+prototype.

I've heard reports like this for many years.

My pet theory is that the discrepancy here is ~10% static types and ~90% memory management. Having a GC (or refcounting or whatever) fully baked into the language so that you don't have to think at all about how values are passed around and stored is a monumental productivity boost. Possibly the biggest win in software engineering productivity in the history of the field.

Re:Selecting a programming language can be a form of prematu... by ptx on Monday November 15, 2021 @05:04PM (#29233439)
Absolutely. I recently translated Microsoft's example code for using the Windows crypto API from C++ to Python, and huge chunks of the code melted away as it was mainly concerned with freeing buffers. Exceptions also helped.
Re:Selecting a programming language can be a form of prematu... by tcbasche on Monday November 15, 2021 @04:28AM (#29225458)
> Python prototypes were usually written by part-time ex-academia Python dabblers

This seems like a monumental level of operational waste. I'd love to hear more about this particular setup

Re:Selecting a programming language can be a form of prematu... by rich_sasha on Monday November 15, 2021 @04:41AM (#29225537)
Well, part-time programmers. Full-time employees, doing mostly semi-academic stuff.
Re:Selecting a programming language can be a form of prematu... by andai on Monday November 15, 2021 @04:25AM (#29225436)
There should be one-- and preferably only one --obvious way to do it.

-PEP 20 -- The Zen of Python

Re:Selecting a programming language can be a form of prematu... by uranusjr on Monday November 15, 2021 @09:01AM (#29227444)
Although that way may not be obvious at first unless you're Dutch.

—The next line

This ZoP line is by far the most misused cliché of all things Python. How is it determine that “prototyping in C++ and rewriting in C++” is not the obvious “one” way? Because you don’t like it? A Zen is intentionally self contradicting to allow introspection, not judge others :)

Re:Selecting a programming language can be a form of prematu... by michaelcampbell on Monday November 15, 2021 @10:01AM (#29228171)
Hold my beer.

-- Django

Re:Selecting a programming language can be a form of prematu... by bierjunge on Monday November 15, 2021 @10:06AM (#29228242)
Amateurs.

-- Perl

Re:Selecting a programming language can be a form of prematu... by jorgeleo on Monday November 15, 2021 @11:48AM (#29229428)
Slow kids

-- assembler

Re:Selecting a programming language can be a form of prematu... by anamax on Tuesday November 16, 2021 @09:58PM (#29248890)
Pot, kettle, black.

-- fpga

Back at you.

-hdl

Re:Selecting a programming language can be a form of prematu... by xscott on Monday November 15, 2021 @08:28AM (#29227078)
I wonder how your C++ would've gone if you had a C++ library of Python-like data types. Something like a 'variant' type that could hold arbitrary integers, strings, and dicts or lists of those (or anything else you commonly used).

You would initially trade some of the C++ performance, but the code shouldn't be more complicated or difficult to write or compile than Python. Then, you'd only need to change the performance sensitive parts to use real C++ arrays or structs.

Re:Selecting a programming language can be a form of prematu... by typon on Monday November 15, 2021 @09:44AM (#29227948)
This is something I do except the slow parts are in Python and the fast parts are in C++ with pybdind11 connecting the two worlds
Re:Selecting a programming language can be a form of prematu... by Kye on Monday November 15, 2021 @09:20AM (#29227681)
I thought the C++ tendency was to optimize performance sensitive parts with C or assembly.
Re:Selecting a programming language can be a form of prematu... by taylodl on Monday November 15, 2021 @10:44AM (#29228693)
C++ is C. We used to optimize with assembly but nowadays with a processor's superpipelined architecture and the compiler's global register optimizations and so forth your inlined assembly is more likely to throw a monkey wrench into the whole works and make everything run slower. It's a better use of your time to look for a better algorithm.
Re:Selecting a programming language can be a form of prematu... by khoobid_shoma on Monday November 15, 2021 @05:57PM (#29234057)
Not really. C++ is not C, nor faster than C. e.g. TCO in C++ is awful due to ctor/dtor (could be mitigated by some compiler hints if available).
Re:Selecting a programming language can be a form of prematu... by xapata on Monday November 15, 2021 @11:19AM (#29229121)
Isn't that what Python is? Except C and not C++.
Re:Selecting a programming language can be a form of prematu... by xscott on Monday November 15, 2021 @01:13PM (#29230524)
No, because you wouldn't have to pay the virtual machine overhead (among others). Another possibility would be using Cython - write the prototype in pure Python, then Cythonize the parts which need to run more quickly.
Re:Selecting a programming language can be a form of prematu... by xapata on Monday November 15, 2021 @08:58PM (#29235747)
There are some new competitors for Cython. The article mentions Numba, which I've been pleased with, and mypyc, which I haven't tried yet.