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

[Tutor] beginning to code

Bill wrote:
> Rick Johnson wrote:
> > I think for most languages an intuitive syntax is not
> > important -- C is such a language, Lisp is such a
> > language, Perl is such a language, and there are many more
> > -- but for Python, intuitiveness is very important.
> >
> I guess it depends on what you mean by "important"
> ("important to the compiler", is a legitimate concern, for
> instance). 

Perhaps for C, but not for Python; at least, not the primary
concern. For instance: the reason C uses curly braces and
demands redundant (from the human POV) semicolons at the end
of statements is for the sake of the machine, not the human.
It is much easier to parse matching sets of braces than to
parse indention, especially when Python allows arbitrary
indention even within the same source file so long as the
individual blocks are consistent. For instance, much to my
chagrin, this Python code produces no syntax errors:
    # Python 2.x
    >>> def funky_indention():
    ...     for k in globals().keys():
    ...            print(k)
    ...     for x in range(5):
    ...      print(x)


> From an intuition perspective, C++ allowing you to separate
> the interface of a class from it's implementation, I would
> say that C++ has it all over Python from the point of view
> of "intuitiveness".

You mean by stubbing-out a base class with virtual methods?
I suppose you could do something similar in Python if it so
pleased you, although, Python does not have virtual methods,
but there is an abc module. I admit, i sometimes wish Python
supported virtual methods. I also find that derived methods
are not intuitive in Python because there is no syntactical
indication when a method is being derived, consider this:

    # Python 2.x
    >>> class Base(object):
    ...     def m1(self):
    ...         pass
    >>> class Derived(Base):
    ...     def m1(self):
    ...         # blah
    ...         pass
    ...     def m2(self):
    ...         # blah
    ...         pass
    ...     def m3(self):
    ...         # blah
    ...         pass
Now, when `Base` and `Derived` are living in two separate
modules, how am i to know (short of opening a source file,
and reading the contents) which methods of `Base` are being
clobbered with the new methods in `Derived`? IMO, Python
should require some sort of declaration when a base class
method is overridden by a derived class's method, and a
comment or other "optional" declaration is insufficient. And
an error should be thrown in absence of such declaration.
(1) This would prevent accidental clobbers, and (2) this
would make the code more intuitive. A few ways to do this
would be:

    (1) A new keyword

    redef m1(self):
        # blah
    (2) An expansion of the decorator syntax
    def m1(self):
        # blah
    (3) Or something else...
> It's much easier to tell what's going on, at a glance, in a
> C++ program.

Have you tried using an editor with a code folding feature?

> I am much newer to Python, but I have provided at least one
> concrete feature supporting my opinion. 

I'm not sure what exactly you're implying here... If the
syntax of a language is not intuitive, there is no way that
a programmer can make it _more_ intuitive, although, making
code less intuitive is easy, and there is a word for that:
"obfuscation". So the intuitiveness of a language begins
with the language _syntax_ and heavily depends on the
uniform _usage_ of source code between various authors;
because no matter how intuitive a language syntax may be, if
two or more authors are allowed to write dissimilar code
that produces the same result, intuitiveness is lost. So
whether or not i single out a specific feature, seems