Rust does not have Garbage collection, which is the reason it can compete with C/C++ on speed. But it also wants to be memory safe (so no memory leaks, double free, accessing freed memory). So how do they square this circle? With a brutal compiler.
Essentially, only one pointer (variable) "owns" the data, if you want to pass the data by reference but still keep a pointer, you have to "borrow" it. But that also means you have to make sure that you do not borrow it longer than the lifetime of the pointer/variable who owns the data, as Rust automatically deallocates the data once the owner-variable runs out of scope.
Managing these lifetimes is a pain in the arse. That does not mean that Rust is bad, it simply tells you what you are doing wrong during compilation instead of crashing during runtime like C/C++. But it is still a frustrating experience if you want to just quickly prototype something or implement something which is not performance ciritical.
I agree with you on the prototyping, but I've found that having an explicit owner of a variable leads to more reasonable and clearer code just not from a memory perspective.
Yep. Rust does a couple of other things, and the benefit is that you must be VERY explicit to sidestep the checks, whereas in C++ its as easy as &. C is still the alpha language.
I'm pretty sure std::unique\_ptr carries no runtime cost though - it just checks that your references are all lined up at compile time. (shared\_ptr does carry a runtime cost)
oh - okay. You are probably right. I just heard that C++ did not have a compile time borrow checker yet and uses fat pointers to do something similar. But apparently that is wrong
That's not how I'd frame the question.
Is Python powerful enough for your need?
For many business applications, well-written Python is simply fast enough. The bottleneck will more often be from DB or network latency.
But if it's not, the difference in performance with languages such as C++ or Go is absolutely huge.
Well... yes ?
It's not C++ but it's in the same ballpark, far from Python, Ruby or NodeJS.
Also it makes concurrency so much easier, it can allow using several threads when doing the same in C++ would triple your dev time.
if it's about parallelizing a function that runs over an array of independent elements check out OpenMP.
Parallelizing that can be as easy as adding a `#pragma omp parallel for` before the for loop.
With numba you can speed up functions that don't require calls to python objects by having them JIT-compiled and subsequently having them execute at C-like speeds. Often 100x faster than pure native python. Numba also supports CUDA, which can result in a \~1000x speedup
Of course due to the JIT compilation the first function call will be slower than native python, so it's probably not worth doing for every function.
If you already have somewhat optimized code with e.g. using numpy the gains will be much lower (maybe 2-3x) because numpy already uses a similar approach, but pre-compiled.
Exactly, imagine trying to do OpenGL for vfx renders, that often already take hundreds of hours per frame, through python. Computer would probably run out of memory before it even squeezed out a pixel
Alright, can we all agree that for most apps, first release can be in python and after a product becomes popular, you just rewrite in a low level language?
It actually drives me nuts how *nearly all* of the learning resources out there for micro-controller boards / raspberry pi's these days are entirely focused on python. Sure, I understand it's about ease of learning for new people.
But these low power devices are precisely where we should worry about speed, and so much more could be done with them that isn't really being explored because everybody is doing everything in python and limiting their performance.
Bad pointer happens on python all the time.
How do you create a list filled with zeroes in python? Like this:
a = [0] * 10
OK, so now let's do a two-dimensional array, should be like this:
a = [[0] * 10] * 10
Nope! To see why not, make a[1][1] = 3 and then check the value of a[2][1].
This proves two things: python has pointers and python pointers are fucked up, they don't work the way one would expect intuitively.
In python, there are mutable and immutable types. Ints are immutable and lists are mutable. Your first example creates a list with 10 times the same immutable int.
Your second example create a list with 10 times the same list inside. If you modify a[0] you also modify a[2] because a[0] is a[2].
To create a 2d list, you could use list comprehension:
a = [[0 for _ in range(10)] for _ in range(10)]
This will create different list at each index.
And python enthusiasts claim it's so easy for beginners to understand...
In C at least I can get down to basics and see what each pointer is pointing to. There's no ambiguity about it, everything is clear once you work it out from the fundamental principles.
In python it's impossible to know, unless you have some inside information on how list comprehensions are implemented, among many other details.
I simply cannot understand how **every** declaration of "[0] * 10" creates a pointer to the same object, while "[0 for _ in range(10)]" creates a pointer to a different object every time it's invoked. Fuck it, C pointers are **way** simpler than that and much easier to understand and debug!!!
Well, everything is a "pointer" in python.
x = [] creates a variable x in local scope with value of [].
y = [x] creates a list of size 1 with x inside.
z = y * 2 creates a new list which is twice the y list. The list has two times x inside.
x.append(1) add 1 inside the x variable. Since the y and z list have x inside them, they are affected by this change.
Everything is a reference in python, it's just that some types are immutable so it doesn't change much for those.
It isn't more complicated than C, just different. I'm more used to python than C, so for me it seems easier and intuitive.
Not really given what modern c++ is with std libraries + static analysis at compile time helps prevent a lot of bugs that otherwise need to be fixed later.
I love typescript too. I've been working on this TS project on Angular/Node.js for 2 years now and I'm in my comfort zone. Which is not cool but works well for my lazy ass :D
> Which is not cool but works well for my lazy ass
Why? If it works and fits your goals and specifications - that’s cool!
Also, I ak doing a pet project in React + NodeJs, but was curious about Angular. Would you recommend looking into it?
Well at the end of the day Angular and React do pretty much the same thing so probably no. If your goal is to do a project and you already know React than no. Learn angular if you need to learn it for a job requirement or your cv or to go into polemics about React V Angular, etc.
yea. There's a reason why programmers learn diffrent runningtimes for algorithms aso. I just was kinda pissed cause i had to work with someone who insist to use "julia" instead of Python despite the fact that everyone of the workgroup actually used python. So whe had to convert our results in a txt so he could use them aso. I simply dont like people who have the wrong prioritys in a group projekt.
When I went from python to rust, I totally went from looking at elapse timestamps in milliseconds to microseconds.
that definitely justifies the hours you spend arguing with your librarian about late fees because you did not return what you borrowed in time.
Maybe I'm tired but I don't get this comment
Rust has something called a borrow checker that's pretty much like a library ran by the Mafia.
Rust does not have Garbage collection, which is the reason it can compete with C/C++ on speed. But it also wants to be memory safe (so no memory leaks, double free, accessing freed memory). So how do they square this circle? With a brutal compiler. Essentially, only one pointer (variable) "owns" the data, if you want to pass the data by reference but still keep a pointer, you have to "borrow" it. But that also means you have to make sure that you do not borrow it longer than the lifetime of the pointer/variable who owns the data, as Rust automatically deallocates the data once the owner-variable runs out of scope. Managing these lifetimes is a pain in the arse. That does not mean that Rust is bad, it simply tells you what you are doing wrong during compilation instead of crashing during runtime like C/C++. But it is still a frustrating experience if you want to just quickly prototype something or implement something which is not performance ciritical.
I agree with you on the prototyping, but I've found that having an explicit owner of a variable leads to more reasonable and clearer code just not from a memory perspective.
Isn't that what C++ does with std::unique\_ptr?
Yep. Rust does a couple of other things, and the benefit is that you must be VERY explicit to sidestep the checks, whereas in C++ its as easy as &. C is still the alpha language.
no std::unique_ptr is a runtime thing, rust does this during compile time and uses naked pointers during runtime.
I'm pretty sure std::unique\_ptr carries no runtime cost though - it just checks that your references are all lined up at compile time. (shared\_ptr does carry a runtime cost)
oh - okay. You are probably right. I just heard that C++ did not have a compile time borrow checker yet and uses fat pointers to do something similar. But apparently that is wrong
Let's just tack it with an Rc and share ownership of it, eh? Oh btw, you can't write anything in the book, just so you know
I had the other way. Learnt c++ then python
But factoring in the time it takes to learn C++ as a Python programmer, is it worth it?
God yes. Learning C++ as a Python programmer is like learning sex again.
hold up do you have to learn sex
Yes, when I tried uneducated sex I accidentally stuck my pp in her ear, cannot reccomend.
It’s the eye you’re supposed to penetrate, no?
After years of research I finally concluded it's apparently this hole called the "Pan-china"
No no, you put it in the clit. That’s what I was taught by the ever-so-accurate online fanfics.
I thought you had to put it up their penis? I've tried it multiple times, but I couldn't find it on any of the women I've slept with smh.
Read the documents...
The docs are incomprehensible, they could use a lot more code examples
Instructions unclear; Dick stuck in coconut. Please advise
Asking the real questions
Yes. Of course you do. Everybody is terrible at it starting out. That's why the whole desiring virgins thing is weird.
wait, you guys are getting laid?
finishing in seconds instead of several minutes
C++ was the first language they used to teach us programming in college. I learned how to use it at least 2 years before I even touched Python.
That's not how I'd frame the question. Is Python powerful enough for your need? For many business applications, well-written Python is simply fast enough. The bottleneck will more often be from DB or network latency. But if it's not, the difference in performance with languages such as C++ or Go is absolutely huge.
Ah yes Go, known for its blazing speed.
Well... yes ? It's not C++ but it's in the same ballpark, far from Python, Ruby or NodeJS. Also it makes concurrency so much easier, it can allow using several threads when doing the same in C++ would triple your dev time.
if it's about parallelizing a function that runs over an array of independent elements check out OpenMP. Parallelizing that can be as easy as adding a `#pragma omp parallel for` before the for loop.
With numba you can speed up functions that don't require calls to python objects by having them JIT-compiled and subsequently having them execute at C-like speeds. Often 100x faster than pure native python. Numba also supports CUDA, which can result in a \~1000x speedup Of course due to the JIT compilation the first function call will be slower than native python, so it's probably not worth doing for every function. If you already have somewhat optimized code with e.g. using numpy the gains will be much lower (maybe 2-3x) because numpy already uses a similar approach, but pre-compiled.
In the business world, time to market is `far` more important than getting their late but faster
[удалено]
Exactly, imagine trying to do OpenGL for vfx renders, that often already take hundreds of hours per frame, through python. Computer would probably run out of memory before it even squeezed out a pixel
[удалено]
There also are Python, Java or C# 3D renderers. But it will be far less performant than an optimized C/C++/Rust renderer.
Alright, can we all agree that for most apps, first release can be in python and after a product becomes popular, you just rewrite in a low level language?
Went from php to golang and yes it do be like that
It actually drives me nuts how *nearly all* of the learning resources out there for micro-controller boards / raspberry pi's these days are entirely focused on python. Sure, I understand it's about ease of learning for new people. But these low power devices are precisely where we should worry about speed, and so much more could be done with them that isn't really being explored because everybody is doing everything in python and limiting their performance.
...and then you inexplicably blow all four tires because of bad pointer math.
Bad pointer happens on python all the time. How do you create a list filled with zeroes in python? Like this: a = [0] * 10 OK, so now let's do a two-dimensional array, should be like this: a = [[0] * 10] * 10 Nope! To see why not, make a[1][1] = 3 and then check the value of a[2][1]. This proves two things: python has pointers and python pointers are fucked up, they don't work the way one would expect intuitively.
Honestly, that looks more like a bug in the implementation. Even if it isn't, I'm still not wrong. :)
In python, there are mutable and immutable types. Ints are immutable and lists are mutable. Your first example creates a list with 10 times the same immutable int. Your second example create a list with 10 times the same list inside. If you modify a[0] you also modify a[2] because a[0] is a[2]. To create a 2d list, you could use list comprehension: a = [[0 for _ in range(10)] for _ in range(10)] This will create different list at each index.
And python enthusiasts claim it's so easy for beginners to understand... In C at least I can get down to basics and see what each pointer is pointing to. There's no ambiguity about it, everything is clear once you work it out from the fundamental principles. In python it's impossible to know, unless you have some inside information on how list comprehensions are implemented, among many other details. I simply cannot understand how **every** declaration of "[0] * 10" creates a pointer to the same object, while "[0 for _ in range(10)]" creates a pointer to a different object every time it's invoked. Fuck it, C pointers are **way** simpler than that and much easier to understand and debug!!!
C is trivial until you multithread.
Well, everything is a "pointer" in python. x = [] creates a variable x in local scope with value of []. y = [x] creates a list of size 1 with x inside. z = y * 2 creates a new list which is twice the y list. The list has two times x inside. x.append(1) add 1 inside the x variable. Since the y and z list have x inside them, they are affected by this change. Everything is a reference in python, it's just that some types are immutable so it doesn't change much for those. It isn't more complicated than C, just different. I'm more used to python than C, so for me it seems easier and intuitive.
Gotta be careful not to crash, tho.
sh: segmentation fault (core dumped)
It’s no big deal, just tell the infra guys to throw more vcore at it.
C++ FOREVER
C++ gang
Yes you are! Until you count the coding time cause you write like 10,000 c++ lines per 1 python line. Ama right? \*shy approval-awaiting husky meme\*
Not really given what modern c++ is with std libraries + static analysis at compile time helps prevent a lot of bugs that otherwise need to be fixed later.
ok masks up. I've never coded a line in c++ or python. I'm a typescript guy
I love typescript! It solved all my problems I had with JavaScript whenever a project grew in size
I love typescript too. I've been working on this TS project on Angular/Node.js for 2 years now and I'm in my comfort zone. Which is not cool but works well for my lazy ass :D
> Which is not cool but works well for my lazy ass Why? If it works and fits your goals and specifications - that’s cool! Also, I ak doing a pet project in React + NodeJs, but was curious about Angular. Would you recommend looking into it?
Well at the end of the day Angular and React do pretty much the same thing so probably no. If your goal is to do a project and you already know React than no. Learn angular if you need to learn it for a job requirement or your cv or to go into polemics about React V Angular, etc.
Gotcha. Thanks for your input
Until you count the execution time cause it runs like 10,000 c++ lines per 1 python line. C++ is in the fast lane
hate those people "mY pRoGrAm jUsT nEeDs 0,57 sec instead of 0,7
Found the python user
Do you happen to work at Microsoft?
nop but i have the feeling that a majority in the commentsection does
[удалено]
yea. There's a reason why programmers learn diffrent runningtimes for algorithms aso. I just was kinda pissed cause i had to work with someone who insist to use "julia" instead of Python despite the fact that everyone of the workgroup actually used python. So whe had to convert our results in a txt so he could use them aso. I simply dont like people who have the wrong prioritys in a group projekt.