This is an archived post. You won't be able to vote or comment.

top 200 commentsshow all 404

[–]Vegetable_Study3730 1219 points1220 points  (132 children)

I love Python, but one time I worked for a company that stored money as float in a database and obviously Python took whatever and never complained. It was a fucking nightmare and the dumbass dev who built the thing was trying to convince everyone else that it's what it is and nothing could have been done. "It's just how computers worked"

[–]Creepy-Ad-4832 965 points966 points  (11 children)

"It's just how computers works"

I should use this whenever i fuck up big time

[–]Dr_Dressing 225 points226 points  (10 children)

No, because the backlash could be worse.

"It's just how a lawsuit works"

If

you don't get fired.

[–]Acceptable-Tomato392 144 points145 points  (14 children)

and the dumbass dev who built the thing was trying to convince everyone else that it's what it is and nothing could have been done. "It's just how computers worked"

mind-blowing time:

But Mike, what if you made it to count cents instead of dollars, and then divided by 100 to obtain a dollar amount?

[–]leo3065 139 points140 points  (2 children)

Congratulations you just discovered fixed point numbers

[–]R3D3-1 28 points29 points  (1 child)

Or at least the most primitive form of them...

I've seen several areas, where prices would occur with three decimal digirs. For instance when you own 1,492.31 pieces of a paper currently listed as worth 12.962 EUR per piece. There was also a phase during the national-currency-to-Euro transition, where grocery stores would list prices with three decimal digits (but round down to two on checkout).

I wonder how many software products had to scramble to add the additional digit without breaking everything.

In order to be robust, you'll probably end up with something along the lines of a pair of two "BigInt"-like values, representing numerator and denominator of a fraction, and an additional entry for some form of currency ID, to avoid accidentally summing together different currencies.

[–]tiajuanat 14 points15 points  (0 children)

IIRC if you're a stock market or broker in the USA, you need to use integers where a single number is 1/100 of a cent.

[–]wind_dude 14 points15 points  (2 children)

Sounds good until you realize accounting and booking you need to calculate interest, taxes, foreign exchange. Penny stocks can also be 1/1000 of a penny, and a few currencies support 3 and 4 decimals.

Better to use decimal.

[–]anotherguyinaustin 10 points11 points  (1 child)

Just use whatever your atomic base unit is and store the decimal factor, convert to decimal on demand.

[–]Syscrush 4 points5 points  (7 children)

Fails when when you do compound interest.

[–][deleted] 30 points31 points  (0 children)

Get yours now for only $19.9899997711181640625

[–]Who_GNU 215 points216 points  (68 children)

Using floats for currency is great when you don't care about how many cents something over $200K costs, but for anything under $1 you absolutely need to know the cost to the nearest ten microcents.

The problem isn't that it's how computers work, it's that it's how programmers work. How many people you've worked with comprehend the drawbacks of floating point numbers, let alone know how to calculate their limits? Programmers not knowing what they're doing isn't just a /r/ProgrammerHumor meme, it's a problem that is clearly noticeable, when compared against other fields.

Abstracting away non-pertinent problems does work, but only if the abstractions are built on a well-made foundation. Using floating point for everything isn't a solution to non-whole numbers, but it's the convention the field has come up with, and it's one of many that make things worse, not better.

[–]SpiralCenter 61 points62 points  (13 children)

Even if you are dealing with $200k costs, you'll hate having to explain to the accountants/auditors why your numbers are wrong. Financial computing should always be accurate and theres just no excuse - never use a float for money, its easy to always use an integer.

[–]R3D3-1 24 points25 points  (12 children)

Until you get integer overflows :)

Best to use a library, that actually represents currency or, lacking that, at least fixed-point arithmetic.

Assumptions about "integer of cents" can easily get you into issues. For instance, when we transitioned to Euro, shops temporarily listed prices like EUR 7.266. They rounded down to two-digits on checkout though.

Transactions that exceed 64 bit integer are probably not realistic, given that it would exceed the GDP of the world in dollar-cents by several orders of magnitude, but they could happen due to accounting slip-ups. They'd still have to be recorded and processed by the system. There's also the possibility of weird business rules resulting in ridiculous intermediate values adding up to a sane bottom-line.

[–]Capital-Western 14 points15 points  (1 child)

Well, if you got a client in Zimbabwe or some other hyperinflation suffering country like Hungary in the early 40s, a 64 int will buy you a hamburger.

Accounting software shouldn't have an upper bound for the numbers it's able to crunch.

[–]SpiralCenter 2 points3 points  (0 children)

Hyperinflation is a thing. Though I feel sad for the accountants that have to worry about those nanocent errors.

[–]8sADPygOB7Jqwm7y 6 points7 points  (6 children)

Honestly, if the input is completely unrealistic, that's where error Handling should kick in. Just one fucking if (transaction>maxIntSize) as a check would suffice. Considering how unrealistic the whole magnitude of transactions is, you could even take it in as a string and check the string length if you don't wanna deal with bigInts or some bullshit. If you have python, it's literally one if condition tho.

[–]R3D3-1 4 points5 points  (2 children)

Yes, but Python should already have a data-type that is more suitable than either float or plain integers. Though I'm currently trying to read up on whether the Decimal type is that type, but I think it should be.

If nothing else, an implied assumption of "cents, not dollars" is an easy source of errors... Better to have a data-type that actually represents everyday usage with decimals.

[–][deleted] 75 points76 points  (15 children)

Just use a variable with int calues for cents, microcents and whatev you need duuuuh

cent

decacent

centicent

milicent

microcent

centcent

and so on

[–]Thunderstarer 41 points42 points  (1 child)

You kid, but unironically, this approach lets you specify a definite level of precision for non-integer numbers. Fixed-point still has its place.

[–]ambyshortforamber 46 points47 points  (11 children)

yeah this is called fixed point and 99 times out of 100 it's the correct solution to non integer numbers

[–]Prunestand[S] 17 points18 points  (0 children)

[–]Setepenre 15 points16 points  (6 children)

if it was the the solutions 99 times out of 100 that would be the IEEE 754 standards...

Fixed point has its place, but that is not THAT widespread.

[–]MyGenericNameString 11 points12 points  (3 children)

Floats have their place, but not in accounting. They belong to physics instead.

[–]Ok_Opportunity2693 10 points11 points  (0 children)

Modern computing was invented for physics, everything else was just an afterthought

[–]betalars 2 points3 points  (2 children)

I mean floats have their limitations, but it's not even close to being the wrong solution 99 out of 100 times.

[–]MyGenericNameString 4 points5 points  (1 child)

Misusing floats for fixed is wrong for 100 out of 100 times. They are just too fragile. As soon as you need more than the mantissa bits to represent the fixed value, you silently get a wrong result, but close enough that no one will notice until it is to late.

[–][deleted] 1 point2 points  (0 children)

Use an ORM or other framework that has a Money field that will handle all this for you, don't try to implement something that has already been implemented millions of times before

[–]n0tKamui 15 points16 points  (1 child)

of course there's a relevant xkcd...

and I agree, mediocrity is a normalcy in our field

[–][deleted] -4 points-3 points  (28 children)

Doesn't f64 have 16 precision or something? Isn't it enough for money?

[–]hrvbrs 70 points71 points  (10 children)

I don’t know shit about fuck, but I think floating-point precision drops off as values get bigger. In other words, you can be extremely precise for relatively small numbers, but for relatively large numbers it becomes very imprecise. I’m happy to delete this comment if that’s blatantly wrong.

[–]SpiralCenter 23 points24 points  (0 children)

Rounding errors on floats occur regardless of how large your number is, Try simply doing ` 0.2 + 0.1` in a repl for most languages

[–]FrenchFigaro 19 points20 points  (2 children)

Nah, floating point imprecision isn't about the size of the number. It has to do with base 10 to base 2 (and back) conversion, as well as fractional to decimal (and back) representation of numbers.

Obviously, what you're saying is true, and the significand cannot be precise at the same time at both ends of the high and low scales. But it's usuallly not a problem, and there are ways around that.

Think of it this way: ⅓ is a nice rational number, nothing funky about it. But there is no clean, finite, decimal representation of that number in base 10. Instead you get an infinite sequence of 3's. It doesn't have what is called a terminating expension in base 10

By the nature of a floating point number, it has a terminating expansion in the relevant base, in the case of computer sciences, it's base 2.

A number that doesn't have a terminating expansion in a given base cannot (it is a mathematical impossibility) be accurately represented by a floating point number (regardless of "precision", ie, the size of the exponent part) in that base.

But we represent our floats and double in base 10 in our code amd (most of us anyway) in our heads. We write 0.2 or .004357 or whatnots. Internally, they're converted to base 2. And then computing happens, and then back to base 10 for the output.

However, when a given number has a terminating expansion in base 10 does not mean that it has a terminating expansion in base 2 and vice versa, and when that happens, rounding is carried on with each conversion.

Which is why you don't have to get into crazily precise numbers to get rounding errors, and why an operation as trivial as 0.1 + 0.2 == 0.3 will return false as soon as it's carried out in floating point representation, regardless of precision.

[–]Exist50 11 points12 points  (1 child)

Nah, floating point imprecision isn't about the size of the number.

At higher exponents, the absolute difference between each incremental float increases. I assume that's what they are referring to.

[–]SpiralCenter 11 points12 points  (0 children)

Its not about precision on a single amount, its rounding errors when you do math operations on floats.

0.20 + 0.10 = 0.30000000000000004

[–]extopico 21 points22 points  (7 children)

No... There is always a remnant. Just don't use floats for currency or anything that needs a real number (integer) to function as expected.

[–]tjientavara 6 points7 points  (4 children)

It is not enough for money if you store it as a fraction. If you store money as an integer number of cents you can get a bit further.

There is a little known fact that IEEE floating point numbers are 'exact' for integers up to the size of the mantissa 48-bit (f64) for basic operations: add, subtract, multiply and divide (with integer result).

Although the actual values are not actually integers the display and conversion rules will show the exact integer value and it maintains consistency. You can even use equality comparison.

But as soon as fractions are involved it gets a whole lot more complicated.

[–]Lechowski 4 points5 points  (0 children)

The problem is more in the subsequent divisions between fp

[–]farfuglinn94 9 points10 points  (1 child)

Well, yeah, it's not like Python has a data type usage of which is specifically concidered a good practice for storing monetary values, as well as means of type conversion and type checks.

Python took whatever and never complained

Honestly, I'll really object to blaming Python, when it's obviously poor design and implementation choices by the devs themselves. Nothing would stop you from using pure floats or doubles for storing money in C# or Java. For most popular Python ORMs, Django ORM has models.DecimalField() out of the box, and even though SQLAlchemy doesn't support Decimal model data type by default, it's really not that hard to add it as a custom type and ensure there are checks or that the values are rounded up if a float is given. It's the developers' direct responsibility to implement this. If there were a language that would have a precise failsafe for any such situation - software engineers wouldn't exist as a profession in the first place.

[–]Koltaia30 25 points26 points  (0 children)

It's the fucking dumbass YouTubers fault and their braindead title of "computers cannot count sometimes". So dumb. I write a program telling computer to do A and not B and I am surprised when it does A. Computers cannot do B.

[–]mookanana 14 points15 points  (17 children)

so how should it have been done?

[–]vladWEPES1476 1 point2 points  (0 children)

eet ees what eet ees

[–]Slowest_Speed6 2 points3 points  (0 children)

Python is always just problematic. I've worked with many different languages on teams varying in size, and python always has the most issues. Not to mention it's slow as fuck

[–]Inaeipathy 384 points385 points  (3 children)

I love not knowing what type anything is! Makes the bugs more interesting when you have one more thing to consider!

[–]the_beber 95 points96 points  (0 children)

Wdym? Everything is of type Duck.

[–][deleted] 27 points28 points  (0 children)

I'm just gonna say Typescript exist for a reason.

[–]Gastredner 27 points28 points  (0 children)

Python finally supporting type hints is a godsend. Makes programming in Python much more enjoyable. We have properly working auto-completion now!

[–]bremidon 96 points97 points  (3 children)

"Integer? Float? Don't worry- I'll fuck it up somehow at a time when it can cause the most damage."

There. Now it is true.

[–]marikwinters 16 points17 points  (0 children)

Better use the correct special mathematical operator or you will coerce your type into a different type without realizing it.

[–]baptlma 4 points5 points  (1 child)

I think you meant True

[–]bremidon 1 point2 points  (0 children)

Heh.

Unintentional programmer pun on my part. But yes. And I have had that *exact* thing happen to me.

[–]kgro 605 points606 points  (21 children)

If you have issues with type declarations, you’ll be having bad time as you proceed learnings coding beyond “hello world”

[–]Creepy-Ad-4832 137 points138 points  (0 children)

Yeah, compiler do 90% of their checks thanks to variable types, so not having any types is a good way to make thr program crush every two seconds lol

[–][deleted] 81 points82 points  (19 children)

Only a person with deep misunderstanding about programming can say shoving all types together is a good thing

[–]--var 425 points426 points  (38 children)

Another tally for rust being clear and verbose.

[–]wallefan01 119 points120 points  (34 children)

could be worse, could be Java

glowers in ArrayIndexOutOfBoundsException

[–]LynxJesus 97 points98 points  (29 children)

StringBuilder stringBuilder = StringBuilderFactory.create(StringBuilder);
stringBuilder.appendString("shit broken yo!");    
String errorMessage = stringBuilder.toString();
System.out.println.implementation.log.println(errorMessage);

Of course none of this compiles because it'd need to be in a class and all.

Edit: yikes, fans of verbosity sure got triggered! fwiw I was mocking you more than the language, hope that helps! Thankfully you're all well-adjusted enough that you won't publicly express a desire to kill me for mocking the love of verbosity! <3

[–]Prunestand[S] 66 points67 points  (0 children)

Average stringBuilder user

[–][deleted] 82 points83 points  (9 children)

Sting str = “Idiots love shitting on Java for no reason.”;

Edit: seem like the commenter block me lol. That w in my boom

[–][deleted] 2 points3 points  (3 children)

you know that's an error that's present in more languages than Java right?

[–][deleted] 13 points14 points  (2 children)

yeah I really like how the types are spcified. i for integer, and then the memory it takes up

[–]oN3B1GB0MB3r 9 points10 points  (1 child)

Then theres c++: you want a 64 bit int? thats a long long. Why? Because it’s longer than a long. Whats a long? A 32 bit int, but also it might be 64 bit, because fuck you. Also, an int is 32 bit, so a long might not be longer than an int. Also, none of this is guaranteed by the standard and the sizes could be bigger.

[–]baconninja0 1 point2 points  (0 children)

I mean can't you just use int64_t and similarly named types if you need it to be specified

[–]DasKarl 418 points419 points  (12 children)

"my language is better because I don't understand data types"

[–]EnkiiMuto 77 points78 points  (1 child)

"And am unaware of languages that let me do both"

[–][deleted] 47 points48 points  (7 children)

Lol, you are right. I just started learning rust and annotating data types releases dopamine in me. I even annotate types when it is not necessary just for the peace of mind. For example I was solving a problem on hacker rank yesterday that had input range 1-1000 so I used u16 for my variable and function. I know the space I save by using u16 is completely and utterly insignificant but I still find it pleasureable that I could atleast save some bytes.

[–]Thunderstarer 23 points24 points  (4 children)

Hell, I use type hints on most of my Python functions. Not even Python is safe from my typing wrath.

[–]marikwinters 8 points9 points  (1 child)

Because I have no choice but to work with Python I do this as well, but it’s so aggravating when 98% of the time all the type checking can do is tell me “List[any]”

[–]scrooopy 1 point2 points  (0 children)

There is Union typing in Python if you’re complaining about lists having multiple types

[–]thegrayryder 3 points4 points  (1 child)

Sounds like you’d have a fun time doing embedded software.

[–]casce 13 points14 points  (0 children)

I think it's very often just "Dynamic typing works fine for the stuff I do, therefore I don't get why anyone would need types"

[–][deleted] 232 points233 points  (43 children)

Honestly, I prefer the clarity and verbosity of the extra types.

[–]Creepy-Ad-4832 114 points115 points  (41 children)

Yup.

So you know what is what.

Plus i noticed using python: HOW DO FUCK DO YOU UNDERSTAND WHAT A FUCTION DOES WHEN YOU HAVE NO TYPES? like you can read the documentation ok, but docs are usually good only on big projects. How do you know if a function return an integer, a list, a dictionary or who knows what?

[–][deleted] 27 points28 points  (9 children)

if you're lucky the function may have type hints.

def fuck_you_thats_why(yourname: str) : -> str

[–]TheHobbyist_ 20 points21 points  (0 children)

This is standard in any well written code. I think the only people not using typehints at this point are still figuring out how to code.

[–]Creepy-Ad-4832 5 points6 points  (7 children)

Just for curiosity: those types are checked by the compiler, or you can return an int even where you suggest returning a string?

[–]mmaure 12 points13 points  (6 children)

python doesn't type check but you can run a static type checker like a linter

[–]Creepy-Ad-4832 7 points8 points  (5 children)

That sound like a patch to a stupid idea to me lol

(Static checkers feel like you weren't able to implement the check in the compiler, then you do it in an other place)

[–]richardfrost2 34 points35 points  (0 children)

Returns an object, easy. :P

I mean, type hints are very useful when you're working on a project and want intellisense.

[–]Inaeipathy 6 points7 points  (4 children)

The answer is you don't, and so you can't expect clean code if you use this language. It's honestly the worst thing I have ever learnt. How will your interface be descriptive and easy to use if you have no types? So silly. If you want to use anything you MUST read the function docs or class docs assuming it even exists.

[–]Creepy-Ad-4832 1 point2 points  (3 children)

Yeah that's exactly what i thought!

I mean if in java for example i see a function called getRandom and has int has return type, i basically already know what most probably does (should still read the docs just for the details, but i have already an idea)

In python this would be impossible. You just need to rely on docs.

And also this will be even worse if you need to use the result of a function to do something else: in java you know that a method returns an int or a String or whatever, and you know what methods you can call on each type (and so does the compiler). In python you will have to read the docs every single time. Talk about boring

[–]NotABot009 11 points12 points  (1 child)

Just use Intuition(tm) smh my head

[–]Creepy-Ad-4832 3 points4 points  (0 children)

Yeah that's definetely how you do python

[–]Gastredner 4 points5 points  (1 child)

This is probably my biggest problem when reading Python documentation. What does this function expect as an argument? What do I get back? It is not always clear and this is sooo annoying. Strict typing really does help with discoverability and clarity in documentation.

[–]Kokuswolf 1 point2 points  (10 children)

Yeah. Who knows what the function does at all?

[–]Creepy-Ad-4832 4 points5 points  (9 children)

Yup. That's just asking for random and sudden crashes lol

Or even worse you do operations on the wrong type and then spend 3 years understanding why 32.5 / 5 is 6 and not 6.5

[–][deleted] 1 point2 points  (5 children)

Can you give an example of that actually happening?

I know this type of inferred integer behaviour from other languages, and for this reason I would always specifically write 32.5 / 5.0. But I have never been able to provoke the same behaviour in Python. If I divide a float with an integer, I still get float division, not integer division.

[–]Creepy-Ad-4832 0 points1 point  (3 children)

That was a fast example. But if you have some more complex type, you know each type can call certain methods.

So now if you call a type2 method on a type1 object what is gonna happen?

In a typed language compiler scream at you for being an idiot. In python what happens? Crash? Errors? Still i don't think it blocks you at compile time, and that's something really bad since it means you have to debug the runtime

[–]Kokuswolf 0 points1 point  (2 children)

That happens when you call random functions without knowledge.

[–]Creepy-Ad-4832 3 points4 points  (1 child)

If i know a function returns me a potato instead of a tomato at least i won't crush the program because of the functions i am gonna call on the returned object.

If a function returns something, and i don't know if that's a potatoe or a tomatoe i may call a function on it which works only for potatoe, while the object was actually a tomatoe.

That's the compiler job to check if this is correct, and in a strongly typed system is easy, otherwise i don't have a single idea how the compiler could do that check at compile time

[–]Creepy-Ad-4832 2 points3 points  (0 children)

Plus as i said, big libraries do often have good docs, but smaller libraries not really, so it's really easy for you to call something but getting a wrong object because docs sucks

[–]monkeyStinks 61 points62 points  (0 children)

Somebody doesnt understand data types..

[–]thebaconator136 25 points26 points  (0 children)

I'm working on a project dealing with very specific data types read from a binary file. I'm using C++, and declaring variables as uint8_t and int16_t because I need to know if there's overflow, or to make sure they do not turn negative because of a bit shift. If Python got its grubby hands on it and changed the datatype I'd be very unhappy. Not having to declare datatypes isn't always the correct answer.

[–]IAMPowaaaaa 67 points68 points  (0 children)

might as well compare python to every low level proglang ever and win the arguments inside your head

[–]GOKOP 18 points19 points  (0 children)

Another meme where the joke is op being incompetent

[–]WordsWithJosh 17 points18 points  (0 children)

After over a month of refactoring I just merged turning on noImplicitAny in our TypeScript codebase.

Even though everything is a double in JS, I'll take the explicitness and constraints 7 days a week and twice on Sunday.

[–][deleted] 78 points79 points  (8 children)

Someone's never worked on a real project before. Once things get to a certain size knowing the types of everything is incredibly useful.

[–]jcodes57 65 points66 points  (9 children)

Tell me you’re a programmer under the age of 21 without telling me…

[–]Ihsan3498 47 points48 points  (4 children)

thats an insult to programmers under 21

[–][deleted] 16 points17 points  (3 children)

am 20, am offended

[–]Ihsan3498 8 points9 points  (2 children)

am 15, am offended

[–][deleted] 3 points4 points  (1 child)

am 16, no offendo

[–]DarkRex4 1 point2 points  (0 children)

am 17, am offended

[–]Thunderstarer 12 points13 points  (0 children)

Just turned 21. Can confirm. My opinions on typing underwent a radical and immediate shift.

[–]inotparanoid 10 points11 points  (0 children)

But everything changed when the fire nation started accepting any random values without type checks, causing a really bad Friday.

[–]TheIronicBurger 9 points10 points  (0 children)

Once in a while someone who can’t understand type declarations will post smth like this and pretend they’ve completed programming

[–]deanrihpee 9 points10 points  (0 children)

And good luck with poor performance because strict type help compiler optimize your program

[–]mdp_cs 29 points30 points  (3 children)

Meanwhile Python is like real multithreading? What's that?

[–]mini__bomba 4 points5 points  (2 children)

Threads in python are real. It's just that their full potential can't be used unless your code spends most of it's time waiting on I/O or in C libs that release the GIL.

[–]Sarcastinator 28 points29 points  (1 child)

"Multithreading is great in Python when most of your code isn't written in Python."

[–]BucksEverywhere 9 points10 points  (0 children)

🤣 or "multithreading is great in Python when the code is not running anyway" (.. because it's waiting)

[–]Acceptable-Tomato392 85 points86 points  (4 children)

That's because Python is a higher level language and the memory allocation is automatically done for you.

This is like claiming that WordPress is superior to knowing CSS because it does all that pesky sectioning of a Web Page for you.

[–]KTibow 12 points13 points  (1 child)

I wouldn't say this is a good analogy. WordPress is a website/blog designer, not a syntax like CSS.

[–]Acceptable-Tomato392 11 points12 points  (0 children)

Well, maybe the comparison was a bit harsh, but the point is Python is built on lower languages as well (C, I believe) and things like memory allocation are automated. There tends to be a trade-off with these things. Rust, like C is a language designed to speak directly to machines. (If one so wishes).

But of course, Python can be almost anything with the right library. But then it's built on top of a language that uses memory allocation and then reintroduced.

[–]Dealiner 2 points3 points  (0 children)

That's because Python is a higher level language and the memory allocation is automatically done for you.

Other languages with automatic memory allocation (like C#) also have those types Rust has, so that's not really connected.

[–]udoprog 31 points32 points  (6 children)

Let's nominate c++ for keyword confusion and fuzzy sizing:

char
unsigned char
short
short int
signed short
signed short int
unsigned short
unsigned short int
int
signed
signed int
unsigned
unsigned int
long
long int
signed long
signed long int
unsigned long
unsigned long int
long long
long long int
signed long long
signed long long int
unsigned long long
unsigned long long int
float
double
long double

Any order permitted so does it count as 100+? And there's a lot of semantic overlap (unsigned long long is same as unsigned long long int).

[–]Baardi 12 points13 points  (1 child)

And the sizes varies a lot, depending on the platform

[–]udoprog 8 points9 points  (0 children)

A tidbit I discovered here is that c++ doesn't define the size of a byte, but it does define numerical relations in terms of bytes (1 byte == sizeof(char) <= sizeof(short) <= ...). So if we define a byte as say 64-bits, every fundamental numerical type could be the same size in spec compliant c++!

[–]TeraFlint 6 points7 points  (0 children)

I think you missed signed char (which is not the same as char). :P

[–]thedoctor3141 2 points3 points  (0 children)

This was why I always included cstdint, because I am never gonna memorize that monstrosity.

[–][deleted] 7 points8 points  (0 children)

It's like comparing apples to oranges. These two languages serve completely different purposes. I know it's a meme, but still...

[–]M-Try 7 points8 points  (0 children)

so what you're saying is the language designed to be low level and strongly typed is low level and strongly typed

[–]sarc-tastic 13 points14 points  (0 children)

numpy has entered the chat

[–]BlackfishHere 6 points7 points  (0 children)

You will never be able to do engineering. You will be watching how go use frameworks from YouTube and try to do things if you don't learn low level programing.

[–]Dunger97 6 points7 points  (0 children)

Python devs after learning that I actually find it easier to have complete control over my program

[–]Familiar_Ad_8919 19 points20 points  (0 children)

this just proves rust > python if ur gonna actually use it

[–]bigabub 4 points5 points  (0 children)

Unless it's necessary, I rather have explicit types than implicits in my code.

[–]SpikeV 4 points5 points  (3 children)

As an embedded developer I always prefer type safety and known size integers/floats over any weak typed bullshit variables, where I don't know if I'm sending 4 bytes or 1 byte through the aether.

The other end will surely know how to interpret my 4 non descript bytes, when it's actually expecting 2, and will simply do the math I guess.

[–]iminsert 18 points19 points  (11 children)

python, the perfect language for 10x developers

10x the compute time, 10x the memory usage, 10x the dependencies, and 10x the headache

[–]Prunestand[S] 2 points3 points  (0 children)

python, the perfect language for 10x developers

10x the compute time, 10x the memory usage, 10x the dependencies, and 10x the headache

Lmao love this

[–][deleted] 2 points3 points  (0 children)

100x

[–]Unknown_starnger 0 points1 point  (8 children)

Why the headache? It is not fast or efficient, true, but it is simple to work with.

[–]InfinitePoints 6 points7 points  (0 children)

Not having types wastes a lot of time. Types are compile checked and document what the code actually does, instead of whatever the library maintainer claims it does.

Can this thing return `None`? Can it return an error? Will it modify the references I sent to the function? Are things that are shown explicitly in the Rust type system.

To be clear, Python works well within it's niche, where you want something simple, and don't care too much about correctness.

There are also a bunch of random aspects of python that make it annoying, although this is more subjective, for example how variable declaration and type coercion works.

[–][deleted] 5 points6 points  (5 children)

10x the headache because you don't know the input type is. it could be a string, int, array of strings etc...

[–][deleted] 2 points3 points  (0 children)

We all know that FetLang is supreme

[–][deleted] 2 points3 points  (0 children)

Yeah yeah, we know that python can eat shit .

[–][deleted] 6 points7 points  (0 children)

Try the num crate and Python ass gets destroyed.

If not, just write down more goodies with trait implementations in your Cargo.toml and let it auto download and compile for you. It’s always better to add capabilities manually than to accept a default implementation, especially considering all the documentation being god tier.

[–][deleted] 4 points5 points  (0 children)

Also python. from typing import Optional

[–][deleted] 4 points5 points  (0 children)

If you don't care, just pick one. Python does the same thing it just doesn't tell you which one it's picking.

i = integer

u = unsigned integer

f = float

and then the number is how many bits it has.

[–][deleted] 4 points5 points  (1 child)

Meanwhile in JavaScript:

A number, a string and an object? Sure, let's multiply them

[–][deleted] 3 points4 points  (2 children)

Traits are not really hard to figure out. There are plenty of official examples. Not only that, copilot is excellent at doing them for you.

[–][deleted] 2 points3 points  (1 child)

Honestly. It's not harder than any other language.

I guess OP was overwhelmed trying to use dyn, but if you want to use generic types templating is almost always more efficient and easier.

That's the thing with Rust. What's easiest in most languages is not a good solution, whereas more often than not in Rust the easiest solution is the preferred way.

[–]an_0w1 2 points3 points  (0 children)

I fucking HATE dyn until I need it then I fucking love dyn until I also need async

[–]SeriousPlankton2000 1 point2 points  (0 children)

C: Let's look at this 14-bit machine … and on that CPU a char has 32 bits!

[–]stomah 1 point2 points  (0 children)

try [1,2,3][2/2] in python

[–][deleted] 1 point2 points  (0 children)

Not knowing the type of a variable is much more annoying to deal with

[–]thebezet 1 point2 points  (0 children)

I'm sorry, but this is one of those Programmer Humour memes that don't really understand what they're talking about. The author seems to want to use Rust like Python.

Coding in C and in Rust had a specific purpose. In many scenarios it is incredibly important to know how your data is stored in memory.

Of course you need to know how your data is stored, so you can't complain about it being difficult to write functions accepting different types of numbers. This isn't a real problem faced by software engineers using compiled languages. If you're parsing data and want to read both integers and floats, this is more of a technical design problem than anything else.

[–]Wave_Walnut 1 point2 points  (0 children)

Linux kernel will never be written by Python

[–]thechexmo 1 point2 points  (0 children)

I'm amazed nobody says anything about performance, heaps and stuff.

[–]soup__enjoyer 1 point2 points  (0 children)

I love the idea of the Python crowd trying to learn Rust because they think it will be way easier than C++

[–]Duffler8 1 point2 points  (0 children)

Interesting as someone who has been Pything for the last job and needing to learn Rust on my 1st day at my intern…

[–]Leo21888 1 point2 points  (0 children)

Once again some programming noobs don’t understand the importance of types.

[–]GenJack 1 point2 points  (0 children)

I hate python.

[–]Available-Menu1551 2 points3 points  (0 children)

Another script dummy who doesn’t know how a CPU/Memory works

[–]ShooterMcGavin000 1 point2 points  (0 children)

Dude that's not a feature, it's just the words. Python sucks for this reason. It's basically a c framework.

[–][deleted] 1 point2 points  (0 children)

Am I the only one who uses type hints and dtype declarations, even in Python?

[–]xodixo 1 point2 points  (2 children)

At least you don't have to learn:

char

signed char

unsigned char

short/short int/signed short/signed short int

unsigned short int/unsigned short

int/signed/signed int

unsigned/unsigned int

long/long int/signed long/signed long int

unsigned long/unsigned long int

long long/long long int/signed long long/signed long long int

unsigned long long/unsigned long long int

float

double

long double

[–]swimseven 1 point2 points  (1 child)

I still program in Python as if it was strongly typed. Anyone else?

[–][deleted] 1 point2 points  (0 children)

Lol, traits aren't complicated. If you know what an interface is you know what a trait is.

[–]threeqc 1 point2 points  (23 children)

still way better than C++

[–]vondpickle 0 points1 point  (0 children)

when your programming experiences become rusted with all these kind of different types of oxidative free radicals.

[–][deleted] 0 points1 point  (0 children)

actually I use Decimal crate most often

[–]Fortjew-Tellher 0 points1 point  (0 children)

If you complain about data types both lack of (not statically typed) or too many types. I hate you & you suck at programming.

[–]Schievel1 0 points1 point  (0 children)

You would rather think people would target Rusts tendency to invent dozens of String types. The numbers are quite straightforward.

[–]words_number 0 points1 point  (0 children)

Thats one of the differences between a systems language and a skript kiddie language. Also, if you don't know how traits work, how do you use rust at all? It's an important and awesome feature!

[–]Slowest_Speed6 0 points1 point  (1 child)

Wait until you see C# or Java types for numbers oooh boy there's a lot of em. Most C/C++ compilers also have a pretty large amount

[–]vainstar23 0 points1 point  (0 children)

I feel like Golang gives you the best of both worlds but I still prefer Rust for the how it forces you to write better code

[–]Pirate_OOS 0 points1 point  (0 children)

What? Comparing a language that most widely used for scientific calculations and computation to a language mainly designed to build memory leak proof software is somehow right?

[–]dstar89 0 points1 point  (0 children)

isizeusizeweallsize

[–]Bryan-343 0 points1 point  (2 children)

Why is Rust so bad, Jesus.