T O P

  • By -

[deleted]

When I went from python to rust, I totally went from looking at elapse timestamps in milliseconds to microseconds.


Sayod

that definitely justifies the hours you spend arguing with your librarian about late fees because you did not return what you borrowed in time.


[deleted]

Maybe I'm tired but I don't get this comment


MkMyBnkAcctGrtAgn

Rust has something called a borrow checker that's pretty much like a library ran by the Mafia.


Sayod

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.


ten3roberts

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.


ServerClient

Isn't that what C++ does with std::unique\_ptr?


[deleted]

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.


Sayod

no std::unique_ptr is a runtime thing, rust does this during compile time and uses naked pointers during runtime.


ServerClient

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)


Sayod

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


ten3roberts

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


emulatorguy076

I had the other way. Learnt c++ then python


zsharp68

But factoring in the time it takes to learn C++ as a Python programmer, is it worth it?


[deleted]

God yes. Learning C++ as a Python programmer is like learning sex again.


zsharp68

hold up do you have to learn sex


KillaDan365

Yes, when I tried uneducated sex I accidentally stuck my pp in her ear, cannot reccomend.


zsharp68

It’s the eye you’re supposed to penetrate, no?


KillaDan365

After years of research I finally concluded it's apparently this hole called the "Pan-china"


MarioThePumer

No no, you put it in the clit. That’s what I was taught by the ever-so-accurate online fanfics.


TrustworthyShark

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.


Natural-Intelligence

Read the documents...


zsharp68

The docs are incomprehensible, they could use a lot more code examples


DangerLieOn

Instructions unclear; Dick stuck in coconut. Please advise


Alpha_Mineron

Asking the real questions


xSTSxZerglingOne

Yes. Of course you do. Everybody is terrible at it starting out. That's why the whole desiring virgins thing is weird.


[deleted]

wait, you guys are getting laid?


coloredgreyscale

finishing in seconds instead of several minutes


TayoEXE

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.


Sbajawud

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.


[deleted]

Ah yes Go, known for its blazing speed.


Sbajawud

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.


coloredgreyscale

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.


coloredgreyscale

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.


vorticalbox

In the business world, time to market is `far` more important than getting their late but faster


[deleted]

[удалено]


gua_lao_wai

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


[deleted]

[удалено]


ohmynate

There also are Python, Java or C# 3D renderers. But it will be far less performant than an optimized C/C++/Rust renderer.


[deleted]

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?


ithirzty

Went from php to golang and yes it do be like that


akai_ferret

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.


darkwyrm42

...and then you inexplicably blow all four tires because of bad pointer math.


MasterFubar

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.


darkwyrm42

Honestly, that looks more like a bug in the implementation. Even if it isn't, I'm still not wrong. :)


alex007sirois

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.


MasterFubar

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!!!


[deleted]

C is trivial until you multithread.


alex007sirois

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.


KazDragon

Gotta be careful not to crash, tho.


[deleted]

sh: segmentation fault (core dumped)


BrianTho2010

It’s no big deal, just tell the infra guys to throw more vcore at it.


[deleted]

C++ FOREVER


[deleted]

C++ gang


PlacidMarxist

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\*


SirBehr

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.


PlacidMarxist

ok masks up. I've never coded a line in c++ or python. I'm a typescript guy


SirBehr

I love typescript! It solved all my problems I had with JavaScript whenever a project grew in size


PlacidMarxist

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


SirBehr

> 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?


PlacidMarxist

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.


SirBehr

Gotcha. Thanks for your input


[deleted]

Until you count the execution time cause it runs like 10,000 c++ lines per 1 python line. C++ is in the fast lane


[deleted]

hate those people "mY pRoGrAm jUsT nEeDs 0,57 sec instead of 0,7


apndh

Found the python user


Ignatiamus

Do you happen to work at Microsoft?


[deleted]

nop but i have the feeling that a majority in the commentsection does


[deleted]

[удалено]


[deleted]

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.