Hacker News new | past | comments | ask | show | jobs | submit login

This is not weak typing. Perl (both 5 and 6) use operators to define type context. It's entirely unambiguous whether you want to add something or concatenate strings because they are different operators.

  "1" + "1" # 2
  "1" . "1" # 11 (~ to concatenate in Perl 6)
  1 + 1 # 2
  1 . 1 # 11
When you perform a string operation on a numeric type, it stringifies the number, when you do a numeric operation on a string, it numerifies the string (and warns if it can't be cleanly done).

This isn't a typing problem, this is a commenting on language without actually knowing how it works problem. But that's nothing new, people have been doing that to Perl for a long time now.




Ah, sorry. Despite having used Perl for years, I'd forgotten how much emphasis it puts on concepts that invoke a high cognitive load.


On the contrary, I think there is a higher cognitive load in having to reason about the behavior that results from using the + operator between two types when their types may differ. e.g., the Wat talk[1].

To be clear, there is a cognitive load to both. One is based on keeping correct type of the variables you are using with the + operator, the other is knowing that numeric addition and string concatenation are not the same thing, and have different operators. Since string concatenation and numeric addition really aren't the same thing, and don't share the same properties, I prefer the different operators.

1: https://www.destroyallsoftware.com/talks/wat


On the contrary, I think there is a higher cognitive load in having to reason about the behavior that results from using the + operator between two types when their types may differ. e.g., the Wat talk[1].

The simple fact that you run out of operators limits how many types can usefully exist. In Python you use + quite reasonably for integers, floats, strings, and arrays. By contrast raw Perl has equivalents only for numbers and strings, and is unable to distinguish between integers and floats. That is why Perl doesn't do exact arithmetic with large integers.

But, you say, Perl allows you to use bigint? Well, yes. And that is internally implemented with the magic of overload. Using that you can have any number of types which overload + to do what they want, and you have all of the same issues as arose in the Wat talk.

It took a long time for me to be convinced, but I am now convinced that typed variables and untyped operators (like Ruby and Python do) is strictly better in practice than untyped variables and typed operators (like Perl does by default). And as for the complexity, it is just something you have to live with.

Want evidence? https://mitpress.mit.edu/sicp/full-text/sicp/book/node48.htm... discussed this exact problem some 30 years ago. I do not believe that the intrinsic problem is being solved any better today than then.


There is nothing "high cognitive load" about having different operators for addition and concatenation.

I think it's simpler.


Who "adds two strings"? You're 1) converting the strings to ints 2) adding the ints.

The possibility of confusion is the part that is already complex.


> Who "adds two strings"?

$timeText = $systemHours . ':' . $systemMinutes;

vs

$durationTimer = $userInputHours + 1;

There ya go.


PHP and other languages have a . vs + distinction.

I would say that the one area where you're right, and you are so very right, is context. Have %/@/$ cause such chaotic (and not terribly consistent, at least outside the core libraries) behavior changes was not worth the improved error messages or cool tricks you can do with it.

This is coming from someone who really likes Perl (5) both in practice and philosophically.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: