News for hackers. Stuff that matters.
Re:The computers are fast, but you don't know it by mrtranscendence on Thursday June 16, 2022 @03:43PM (#31770068)
> And in the end, the code seems to run "fast enough" and nobody involved really notices that what is running in 750ms really ought to run in something more like 200us.

Nobody has created a language that is both thousands of times faster than Python and nearly as straightforward to learn and to use. The closest thing I know of might be Julia, but that has its own performance problems and is tied closely to its AI/ML niche. Even within that niche I'm certainly not going to get most data scientists to write their code in C or C++ (or heaven forbid Rust) to solve a performance impediment that they've generally been able to work around.

It's great that you've been able to switch to higher-performance languages, but not everyone can do that easily enough to make it worth doing.

Re:The computers are fast, but you don't know it by morelisp on Thursday June 16, 2022 @03:55PM (#31770203)
The "iterate from notebook to production" process which is common everywhere but the largest data engineering groups rules out anything with manual memory management from becoming popular with data science work.

Some data scientists I know like (or even love) Scala, but that tends to blow up once it's handed over to the data engineers as Scala supports too many paradigms and just a couple DSs will probably manage to find all of them in one program.

We use Go extensively for other things, and most data scientists I've worked with sketching ideas in Go liked it a lot, but the library support just isn't there, and it's not really a priority for any of the big players who are all committed to Python wrapper + C/C++/GPU core, or stock Java stacks. (The performance also isn't quite there yet compared to the top C and C++ libraries, but it's improving.)

Re:The computers are fast, but you don't know it by ishjoh on Thursday June 16, 2022 @04:12PM (#31770416)
I love scala and wish it was more popular. I've made piece with java at this point as it slowly adopts my favorite parts of scala but I miss how concise my code was.
Re:The computers are fast, but you don't know it by stefanos82 on Thursday June 16, 2022 @03:53PM (#31770170)
> Nobody has created a language that is both thousands of times faster than Python and nearly as straightforward to learn and to use.

Not Python-based, but Lua-based is Nelua [1]

If you like Lua's syntax, LISP's metaprogramming abilities, and C's performance, well there you have it!

[1] https://github.com/edubart/nelua-lang

Re:The computers are fast, but you don't know it by alar44 on Thursday June 16, 2022 @04:40PM (#31770719)
I think that's my argument. If a developer thinks C or C++ is really that difficult and they can only write effectively in Python, they're a shitty developer and the world seems to be jam packed with them.
Re:The computers are fast, but you don't know it by Gibbon1 on Thursday June 16, 2022 @03:58PM (#31770242)
C# is faster than python and as easy to use.
Re:The computers are fast, but you don't know it by fatnoah on Thursday June 16, 2022 @04:29PM (#31770611)
As a long-time C# user who started life with coding for embedded systems with C, graduated to C++ business tiers, and then on to C#, my personal crusade has always been to show that it's very possible to make things go pretty fast with C#.

One of my favorite moments happened after my C#-based back-end company was acquired by an all-[FASTER LANGUAGE] company. We had to connect our platforms and hit a shared performance goal of supporting 1 billion events/month, which amounted to something like (IIRC) 380 per second. Our platform hit that mark running on 3 server setup w/2 Amazon Medium FE servers and a SQL backend. The other company's bits choked at 10 per second, running on roughly 50x the infra.

Poorly written and architected code is a bigger drag than the specific language in many cases.

Re:The computers are fast, but you don't know it by dataflow on Thursday June 16, 2022 @04:10PM (#31770383)
As nice as it is, C# is definitely not as easy to use as Python.
Re:The computers are fast, but you don't know it by radicalbyte on Thursday June 16, 2022 @04:20PM (#31770505)
If you're using an IDE (Rider or Visual Studio) and avoid the Enterprise frameworks, then it's much easier to use than Python. Tooling makes a huge difference, no more digging through the sometimes flakey Python documentation and cursing compatibility issues with random dependencies not supporting Apple Silicon.
Re:The computers are fast, but you don't know it by dataflow on Thursday June 16, 2022 @04:28PM (#31770596)
I agree tooling makes a huge difference but I specifically said this with the understanding that you're using C# with Visual Studio. Some stuff will be easier in C#, but a lot of other stuff just isn't as easy as in Python.

At the risk of setting up a strawman for people to punch down, try comparing how easy it is to do the equivalent of something like this in C#, and feel free to use as much IDE magic as you'd like:

  x = [t[1] for t in enumerate(range(1, 50, 4)) if t[0] % 3 == 0][2:]
Was it actually easier?

There's a million other examples I could write here, but I'm hoping that one-liner will be sufficient for illustration purposes.

Re:The computers are fast, but you don't know it by eterm on Thursday June 16, 2022 @04:39PM (#31770716)
Here's a one liner in c# for that:

    Enumerable.Range(1,50).Where((x,i) => i % 4 == 0).Where(e => e % 3 == 0).Skip(1).Select(e => e+4)


Okay, so you might consider that last e+4 cheating and against the spirit, but I couldn't be bothered to spend money upgrading my linqpad to support the latest .net with Enumerable.Chunk which makes taking two at a time easier for the first part.

Edit: more in spirit:

    Enumerable.Range(1,50).Where(e => e % 4 == 0 && e % 3 == 0).Skip(1).Select(e => e + 1)
Re:The computers are fast, but you don't know it by Jtsummers on Thursday June 16, 2022 @05:18PM (#31771091)
If I understand dataflow's example correctly you don't need the Select at the end:

  var x = Enumerable.Range(1,50)
          .Where((num, index) => num % 4 == 1 && index % 3 == 0)
          .Skip(2)
          .ToArray();
That computes the same thing as their Python snippet: [25,37,49]. Of course, what this is actually computing is whether the number is congruent to 1 modulo 4 and 3 so it was a weird example, but here's how you'd really want to write it (since a number congruent to 1 modulo 4 and 3 is the same as being congruent to 1 module 12):

  var x = Enumerable.Range(1,50)
          .Where(num => num % 12 == 1)
          .Skip(2)
          .ToArray();
Rewriting that Python example to be a bit clearer for a proper one-to-one comparison:

  y = [t for t in range(1, 50, 4) if t % 3 == 1][2:]
That enumerate wrapper was unnecessary. I don't recall a way, in LINQ, to generate only every 4th number in a range, but I also haven't used C# in a few years so my memory is rusty on LINQ anyways.
Re:The computers are fast, but you don't know it by eterm on Thursday June 16, 2022 @05:44PM (#31771359)
You're right, the maths simplifies it a lot. I rushed out a one-liner without much analysis, and eventually come to the same conclusion.

There's no Range method that takes (start, stop, step) but it's trivial enough to write one, it's a single for loop and yield return statement.

We can even trigger the python users by doing it in one line ;)

    public static class CustomEnumerable { public static IEnumerable<Int32> Range(int start, int stop, int step) {for (int i = start; i < stop; i+=step) yield return i;}}
Try writing your function definitions on one line in python!
Re:The computers are fast, but you don't know it by 369548684892826 on Thursday June 16, 2022 @06:25PM (#31771757)
> LINQ, to generate only every 4th number in a range

Maybe something like this?

    Enumerable.Range(0,49).Select(x => 4*x + 1)
Re:The computers are fast, but you don't know it by Jtsummers on Thursday June 16, 2022 @06:31PM (#31771801)
Yeah, that would work, throw it before the Where clause and change 49. Range here doesn't specify a stopping point, but a count of generated values (this makes it not quite the same as Python's range). So you'd want:

  Enumerable.Range(0,13).Select(x => 4 * x + 1).Where((e, i) => i % 3 == 0).Skip(2)
And that's equivalent to the original, short of writing a MyRange that combines the first Range and Select. Still an awful lot of work for generating 3 numbers.
Re:The computers are fast, but you don't know it by dataflow on Thursday June 16, 2022 @05:27PM (#31771192)
> num % 12

> That enumerate wrapper was unnecessary.

I'm surprised you didn't go all the way and just write

  x = [25, 37, 49]
and tell me the rest of the code was unnecessary!
Re:The computers are fast, but you don't know it by Jtsummers on Thursday June 16, 2022 @05:45PM (#31771377)
I mean, was it necessary? Your original Python expression was pretty obfuscated for such a simple calculation.
Re:The computers are fast, but you don't know it by dataflow on Thursday June 16, 2022 @05:50PM (#31771423)
Are you actually suggesting I didn't realize I could've written x = [25, 37, 49], or what?

Surely the point of the example wasn't "find the optimal way to calculate that particular list of numbers"?

Re:The computers are fast, but you don't know it by Jtsummers on Thursday June 16, 2022 @05:56PM (#31771479)
No, I'm suggesting that your original example was a great example of obfuscated Python. Even supposing that you wanted to alter the total number of values generated and the number of initial values to skip, you're doing unnecessary work and made it more convoluted than necessary:

  def some_example(to_skip=2, total_count=3):
    return [n * 12 + 1 for n in range(to_skip, to_skip+total_count)]
There you go. Change the variable names that I spent < 1 second coming up with and that does exactly the same thing without the enumeration or discarding values. In a thread on how computer speed is wasted on unnecessary computation, it seems silly that you're arguing in favor of unnecessary work and obfuscated code.
Re:The computers are fast, but you don't know it by dataflow on Thursday June 16, 2022 @04:44PM (#31770764)
Nah that part I'm not worried about. The "cheating" is omitting the rest of the line. What you really needed was:

  var y = Enumerable.Range(1, 50).Where((x, i) => i % 4 == 0).Where(e => e % 3 == 0).Skip(1).Select(e => e + 4).ToArray();
Compare that against:

  y = [t[1] for t in enumerate(range(1, 50, 4)) if t[0] % 3 == 0][2:]
It's almost twice as long, and doesn't exactly make up for it with readability either.
Re:The computers are fast, but you don't know it by dmitriid on Thursday June 16, 2022 @05:18PM (#31771095)
What you're missing is that C# example works on any Enumerable. And it's very hard to explain how damn important and impressive this is without trying it first.

Yes, it's more verbose, but I can swap that initial array for a List, or a collection, or even an external async datasource, and my code will not change. It will be the same Select.Where....

Re:The computers are fast, but you don't know it by dataflow on Thursday June 16, 2022 @05:23PM (#31771137)
> What you're missing

I'm not missing it.

> is that C# example works on any Enumerable. And it's very hard to explain how damn important and impressive this is without trying it first.

Believe me I've tried (by which I mean used it a ton). I'm not a newbie to this. C# is great. Nobody was saying it's unimportant or unimpressive or whatever.

> Yes, it's more verbose, but I can swap that initial array for a List, or a collection, or even an external async datasource, and my code will not change

Excellent. And when you want that flexibility, the verbosity pays off. When you don't, it doesn't. Simple as that.

Re:The computers are fast, but you don't know it by dmitriid on Thursday June 16, 2022 @05:34PM (#31771270)
> Excellent. And when you want that flexibility, the verbosity pays off. When you don't, it doesn't. Simple as that.

It's rarely as simple as that. For example, this entire conversation started with "At the risk of setting up a strawman for people to punch down, try comparing how easy it is to do the equivalent of something like this".

And this became a discussion of straw men :) Because I could just as easily come up with "replace a range of numbers with data that is read from a database or from async function that then goes through the same transformations", and the result might not be in Python's favor.

Re:The computers are fast, but you don't know it by eterm on Thursday June 16, 2022 @04:47PM (#31770784)
It's not "twice as long" in any syntactic sense, and readability is easily fixed:

    Enumerable.Range(1,50)
        .Where(e => e % 4 == 0 && e % 3 == 0)
        .Skip(1)
        .Select(e => e + 1)

That's very understandable, it's clear what it does, and if your complaint is that dotnet prefers to name expressions like Skip rather than magic syntax, we can disagree on what make things readable and easy to maintain.
Re:The computers are fast, but you don't know it by dataflow on Thursday June 16, 2022 @04:49PM (#31770800)
It's literally "twice as long" syntactically. 120 vs. 67 characters.

And again, you keep omitting the rest of the line. (Why?) What you should've written in response was:

  var y = Enumerable.Range(1,50)
      .Where(e => e % 4 == 0 && e % 3 == 0)
      .Skip(1)
      .Select(e => e + 1)
      .ToArray();
Compare:

  y = [t[1] for t in enumerate(range(1, 50, 4))
       if t[0] % 3 == 0][2:]
And (again), my complaint isn't about LINQ or numbers or these functions in particular. This is just a tiny one-liner to illustrate with one example. I could write a ton more. There's just stuff Python is better at, there's other stuff C# is better at, that's just a fact of life. I switch between them depending on what I'm doing.
Re:The computers are fast, but you don't know it by radicalbyte on Thursday June 16, 2022 @06:03PM (#31771566)
There's not a lot of difference if you use the query syntax in C# (assuming you add an overload to Enumerable.Range() to take the skip) - only no-one uses that because it's ugly. Also really nice that the types are checked + shown by tooling, as is the syntax.

I use Python a lot for scripting - what it lacks in speed of development/runtime it gains in being more accessible to amateurs and having less "enterprise" style libraries (particularly with cryptographic libraries, MS abstract way too much whilst Python just has think wrappers around C). That makes Python a strong scripting language for me. PyCharm is really nice too.

For real work? C# is better as long as you have either VS or Rider. Really dislike the VS Code experience (these JS-based editors are slow and nowhere near as nice a Rider) so then I can understand why people would avoid it.

Re:The computers are fast, but you don't know it by eterm on Thursday June 16, 2022 @05:14PM (#31771052)
The ToArray is unneccessay, it's much more idiomatic dotnet to deal with IEnumerable all the way through.

The only meaningful difference in lengths is that C# doesn't have an Enumable.Range(start, stop, increment) overload but it's easy enough to write one, and then it'd be essentially the same length.

Re:The computers are fast, but you don't know it by dataflow on Thursday June 16, 2022 @05:15PM (#31771072)
"Unnecessary"? You can't just change the problem! I was asking for the equivalent of some particular piece of code using a list, not a different one using a generator. Sometimes you want a generator, sometimes you want an array. In either language.
Re:The computers are fast, but you don't know it by eterm on Thursday June 16, 2022 @05:33PM (#31771253)
This is a silly argument, you're asking for a literal translation of a pythonic problem without allowing the idioms from the other languages.

If you were actually trying to solve the problem in dotnet, you'd almost certainly structure it as the Queryable result and then at the very end after composing run ToList, or ToArray or consume in something else that will enumerate it.

We can also shorten it further to:

    Enumerable.Range(1, 50)
        .Where(e => e % 12 == 1)
        .Skip(2)
        .ToList()
Now even including the ToList it's now just four basic steps:

Range, Filter, Skip, Enumerate.

Those are the very basics, all one line if wanted. It doesn't get much more basic than that, and I'd still argue it's easier for someone new to programming to see what's going on in the C# than the python example.

edit: realised the maths simplifies it even further.

Re:The computers are fast, but you don't know it by saberience on Friday June 17, 2022 @04:49AM (#31775657)
The big problem is that while shorter, the Python statement itself looks obfuscated, confusing, and hard to read. C# is a bit longer but way clearer.

For me, that it's possible to write such ugly and hard to understand statements isn't an advantage of a language, it's a foot-gun.

Re:The computers are fast, but you don't know it by radicalbyte on Thursday June 16, 2022 @06:15PM (#31771683)
There's very little difference between the two as long as you're using modern versions of both and add your own functions to fill any API gaps and are using type hinting properly in Python. My C# tends to be "larger" because I use more vertical whitespace and pylint is rather opinionated.. :)

Where you can complain about C# - and I do - is where you're having to write (or work with) code which has been force to stick to strict architectural and style standards. That makes code-bases which are very hard to understand for newbies and are verbose.

On the flip side, once you start doing anything even slightly interesting with Python you run into the crappy package management. The end result of which is lots of frustration getting projects working and a lot of time wasted on administration vs work.

Re:The computers are fast, but you don't know it by pelorat on Thursday June 16, 2022 @06:00PM (#31771530)
But who compares Python with C#, they are not even in the same league? Python is a glorified bash scripting replacement with a mediocre JIT engine. Modern C# is faster than Go which is what it is competing against.
Re:The computers are fast, but you don't know it by doliveira on Thursday June 16, 2022 @07:21PM (#31772209)
Does Python even have JIT?
Re:The computers are fast, but you don't know it by gpderetta on Friday June 17, 2022 @06:26AM (#31776223)
certainly not the standard CPython.
Re:The computers are fast, but you don't know it by radicalbyte on Thursday June 16, 2022 @04:17PM (#31770467)
I'd argue easier and it plays much better cross CPU than Python. Once you pass the initial JIT phase it's also extremely fast.

As the sister post says: Go is in the same class as C# only it's a bit verbose/ugly in comparison but it compiles to native machine code..

Re:The computers are fast, but you don't know it by monkpit on Thursday June 16, 2022 @04:10PM (#31770379)
Apparently Jupyter works with .net now. Cool
Re:The computers are fast, but you don't know it by divan on Thursday June 16, 2022 @03:46PM (#31770090)
Go hit a really sweet spot here.
Re:The computers are fast, but you don't know it by pjmlp on Friday June 17, 2022 @02:35AM (#31774777)
It is called Common Lisp, maybe you have heard of it.
Re:The computers are fast, but you don't know it by V1ndaar on Thursday June 16, 2022 @06:16PM (#31771690)
I don't know, but imo Nim begs to differ.
Re:The computers are fast, but you don't know it by lmm on Friday June 17, 2022 @01:22AM (#31774384)
I was able to convert a couple of my data scientist colleagues over to using Scala (given that they were writing code for our Spark cluster it seemed like a no-brainer compared to Python or R). It's not thousands of times faster but it might be ten or a hundred times faster, and a lot of the time you can write the very same code aside from punctuation (and even that difference is smaller in Scala 3, although I don't think Spark has moved to that yet).
Re:The computers are fast, but you don't know it by Dylan16807 on Friday June 17, 2022 @03:09AM (#31775012)
Those speed differences don't come from language, they come from using terribly wrong data structures and algorithms.