this post was submitted on 21 Jul 2023
1 points (52.6% liked)

Programming

16975 readers
1288 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities [email protected]



founded 1 year ago
MODERATORS
1
How helpful languages create bugs (10maurycy10.github.io)
submitted 1 year ago* (last edited 1 year ago) by [email protected] to c/[email protected]
top 7 comments
sorted by: hot top controversial new old
[–] [email protected] 10 points 1 year ago (1 children)

I disagree with the author on operator overloading. They claim that this function in C

float foo(float a, float b) {
	return a+b;
}

is perfectly clear because you know it's doing floating point addition, while this function in Python isn't

def foo(a, b):
	return a + b

because you don't know if it's floating point addition, integer addition, or string concatenation, and what happens if the inputs are different types?

I think that's fundamentally mistaken. You could also ask of the C version if it's doing normalized floating point addition, denormalized floating point addition, infinity addition, or NaN propagation. What happens if you mix different types of floats? And the answer is that it doesn't matter. These are all just aspects of floating point addition. It returns the most sensible result in whatever format is best to hold that value, and you don't need to worry yourself about how floats are stored under the hood.

The same is true of the Python version. It doesn't matter if it's integer addition or floating point addition or string concatenation. Those are just different aspects of the addition operator and it returns the most sensible result in whatever type is best to hold that value.

[–] [email protected] 3 points 1 year ago (1 children)

Agreed. I think operator overloading is a necessary feature in any math-oriented or general-purpose language. Being able to write formulae the same way as they're written in the source paper is a huge boon to readability.

[–] [email protected] 1 points 1 year ago

Totally agree, trying to use BigInt in Java sucks because there's no operator overloading

[–] [email protected] 2 points 1 year ago (1 children)

This post is overlaps ...

*This post overlaps
I am not sure I want to read the rest.

[–] [email protected] 4 points 1 year ago (1 children)

There are a ton of typos in this post, missing semicolons, "you" instead of "your", "then" instead of "than"... that's just the first sentence

[–] [email protected] 1 points 1 year ago

Also Vector2f instead of Vector3f for the cross product example. I'll give them the benefit of the doubt that that's a typo instead of them not knowing what a cross product is.

[–] [email protected] 1 points 1 year ago

Honestly, I did not find that particularly convincing. Lot of typos and leaps in logic. The point is probably kind of true?!?