Hello,
I wanted to just write a quick comment, but it turned into an essay,
sorry. ^^
Le 08/06/2018 �� 16:35, Nicolas Cellier a ��crit��:
Naming variables/arguments according to their type is only half a
solution I think.
Because there are actually two things I would like to know about a
variable/argument when reading code: its type and its meaning.
For example, knowing that an argument named "anInt" is an integer is
nice, but I would also like to know that it's the number of dice the
method has to roll. The two information are very useful to quickly
understand the code.
From what I've seen in Pharo, variables are usually named after
their meaning, while method argument are named after their type, but
in an ideal world I would like to know both the type and the meaning
of both the variables and the arguments.
That's in my opinion one of the advantages of explicit types for
reading code: you write the type besides the variable/argument, so
the name of the variable/argument can describe its meaning and I
have both informations.
I would agree with your colleagues. I got stuck countless times when
reading pharo code, because there was a message send to a variable I
didn't know the type of, so I couldn't know which method was being
called (because there were multiple methods with that name in the
system). So the only solution was to place a breakpoint and get that
method to be executed. This is not so easy (at least for me) in
programs that are not really simple, because:
1) I need to have this method executed in its "normal use
environment". I can't just execute it with dummy values as argument,
because that will affect the values the variables will take.
2) I can look into tests, but since I don't know the program, I have
no idea which tests to run to execute the piece of code.
So in general, it's either asking someone that knows how the program
work, or spending a lot of (annoying) time figuring out how the
entire program flows values to get the type of that one variable.
Thomas