Why isn’t __new__ in Python new-style classes a class method?

__new__ being static method allows a use-case when you create an instance of a subclass in it: return super(<currentclass>, cls).__new__(subcls, *args, **kwargs) If new is a class method then the above is written as: return super(<currentclass>, cls).new(*args, **kwargs) and there is no place to put subcls. I don’t really see when that would be a … Read more

Why don’t languages raise errors on integer overflow by default?

In C#, it was a question of performance. Specifically, out-of-box benchmarking. When C# was new, Microsoft was hoping a lot of C++ developers would switch to it. They knew that many C++ folks thought of C++ as being fast, especially faster than languages that “wasted” time on automatic memory management and the like. Both potential … Read more

Lua operators, why isn’t +=, -= and so on defined?

This is just guesswork on my part, but: 1. It’s hard to implement this in a single-pass compiler Lua’s bytecode compiler is implemented as a single-pass recursive descent parser that immediately generates code. It does not parse to a separate AST structure and then in a second pass convert that to bytecode. This forces some … Read more

Why are there no sorted containers in Python’s standard libraries?

There’s also a python sortedcontainers module that implements sorted list, dict, and set types. It’s very similar to blist but implemented in pure-Python and in most cases faster. >>> from sortedcontainers import SortedSet >>> ss = SortedSet([3, 7, 2, 2]) >>> ss SortedSet([2, 3, 7]) It also has functionality uncommon to other packages: >>> from … Read more

Why Is Dynamic Typing So Often Associated with Interpreted Languages?

Interesting question. BTW, I’m the author/maintainer of phc (compiler for PHP), and am doing my PhD on compilers for dynamic languages, so I hope I can offer some insights. I think there is a mistaken assumption here. The authors of PHP, Perl, Python, Ruby, Lua, etc didn’t design “interpreted languages”, they designed dynamic languages, and … Read more

Why are default arguments evaluated at definition time? [duplicate]

The alternative would be quite heavyweight — storing “default argument values” in the function object as “thunks” of code to be executed over and over again every time the function is called without a specified value for that argument — and would make it much harder to get early binding (binding at def time), which … Read more

Why did Matz choose to make Strings mutable by default in Ruby?

This is in line with Ruby’s design, as you note. Immutable strings are more efficient than mutable strings – less copying, as strings are re-used – but make work harder for the programmer. It is intuitive to see strings as mutable – you can concatenate them together. To deal with this, Java silently translates concatenation … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)