Hacker Newsnew | past | comments | ask | show | jobs | submit | dsemi's commentslogin

Python type annotations were added to be used by an external type checker, so no they are not enforced by the interpreter itself.

This was an explicit decision: https://peps.python.org/pep-0484/#non-goals


> I don't see the difference honestly. both are pretty loose.

There's a clear difference, in PHP 1 + "1" is 2, in Python it's a TypeError, (and as a bonus, in Javascript 1 + "1" is "11").

The definition of "strongly typed" being used is related to type coercion, not type inference. In PHP the string is being coerced to an integer, but Python requires you to explicitly say 1 + int("1") if you want to add the numbers together. This can be helpful to developers because it requires you to make a decision about what behavior you actually want rather than assuming you want to add two numbers or concatenate strings when you may have wanted the opposite.


String concatenation is probably the most reasonable result aside from a type error given how + is used in JS for concatenation elsewhere, but JS actually gets funny.

  "1"*2 // => 2 (not "2")
  "1"*2+3 // => 5
  "1" - 2 // => -1
  "9"/3 // => 3
  "9" + 3 // => "93"
So some mathematical operators will convert string parameters to a number, but not +.


What's the difference between PHP giving "2" as the result of 1 + "1" and Python giving "999" as the result of "9" * 3?


Would be interested to see how cl-ppcre compares as I've often heard people praise its performance.


Me too! I ran out steam adding engines. If anyone wants to take a crack at this, instructions are here: https://github.com/BurntSushi/rebar/blob/master/CONTRIBUTING...

Basically, you "just" need to build a Lisp program that accepts a simple format on stdin, and then repeatedly executes the benchmark given. Then it just needs to print out the time and result of each sample collected. Finally, you need to tell rebar how to build and run the program.


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

Search: