[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

"static" declaration



In our discussions of what makes a lanaguage "lightweight", one of the
things about Java that was condemned as "heavyweight" was the need to
have "static" declarations, or at least the fact that you need to say
"static" when declaring "main".

I have a new job as of a month ago, and one of the my tasks has been
to make some changes to an existing corpus of Perl code.  So, after
many years of dodging and weaving, I have finally taken the time to
learn Perl, and I am now reading and attempting to comprehend a bunch
of existing Perl code.

Perl has methods.  Some methods are, in fact, what Java would call
"static", and some are not.  But there is no "static" declaration in
Perl (or, at least, in the local "dialect", i.e. the particular subset
of Perl that's used around here and the set of programming conventions
for Perl that are used around here).

I have found that when reading code, it is quite confusing to try to
figure out what a method is doing if you cannot tell, up front,
whether it is "static" or not.  From the point of view of a person
trying to read some code, Java's "static" declaration and the fact
that it is *mandatory* is a Good Thing.  If the mandatoryness of the
declaration means that Java is heavier-weight, then the dogma of
lightweight good, heavyweight bad is called into question to at least
some extent.

More broadly, the lack of declarations in Perl makes it a lot harder
to read the code.  For example, the code I am reading is very clearly
object-oriented programming with classes and instances of classes in
the utterly classical Smalltalk sense of those words.  However, there
is no place I can look to find the answer to the question "what are
the instance variables of this class", since any imperative method
anywhere is free to just add a new one at any time.  So I am forced to
trace through all the imperative paths in order to be able to draw my
nice little notes in my notebook that say what the classes are and
what their instance variables are.  The need to do this is definitely
making my job a lot harder and I am not enjoying it.  I really wish
that all the code that I am currently working on had been written in
Java instead of Perl (if those two alternatives be the only choices),
"lightweight" be damned.