bc at freeuk.com
Wed Mar 5 12:28:31 CET 2014
"Steven D'Aprano" <steve+comp.lang.python at pearwood.info> wrote in message
news:5315eec0$0$29985$c3e8da3$5496439d at news.astraweb.com...
> On Tue, 04 Mar 2014 13:30:04 +0000, BartC wrote:
>> Isn't creating classes in Python similar to creating types elsewhere?
> Depends on the type: I suppose you can draw an analogy between records or
> structs and classes with no methods.
> But I'm not talking about creating types, I'm talking about type
> int x=2; # 2 is an int? Who would have guessed!
Think of the int as a 'var' then:
Now you're just declaring the names. But writing 'var' as 'int' is exactly
the same amount of work.
However, in the sorts of languages that require you to describe types in
this much detail, then the exact kind of type can be important:
float/integer, signed/unsigned, short/long, character/numeric etc.
Especially when declaring an array or struct element, or a pointer; in these
cases, providing a sample value in initialisation data is more awkward (for
one thing, because you need to initialise the instance, whereas a struct is
usually declared separately as a type).
But I agree that in many cases, an initialised declaration *could* often be
used to infer the likely type without too much trouble:
var x=2 # integer
var y=3.0 # real
var z="A" # probably, a C-style string pointer ('char*')
(And since I'm working on such a language at the moment, I felt obliged to
implement exactly this. And yes, with 10 minutes' effort, something like
this was working, to prove my assertion.
However it is not satisfactory, which is one reason why no well-established
static language is likely to adopt such a feature. It is just too untidy,
too ad-hoc and undisciplined, to say that usually you need to provide an
exact type, but sometimes, in such and such an instance, you don't need to
More information about the Python-list