Re: regex into str

From: Diez B. Roggisch (deetsNOSPAM_at_web.de)
Date: 08/29/04


Date: Sun, 29 Aug 2004 22:51:21 +0200

Hi,

> Programming causes bugs. That's not a reason to disallow programming.

Well, with that attitude I suggest you start coding in assembler - all
freedom you can imagine, no rules. Every bit is subject to your personal
interpretation. Or C, which is basically assembler with more names and
curly braces.

But for some reasons people started developing and using higher level
languages, that forbid certain techniques - and everytime somebody yelled
"I want to be free to do what I want" - python has its very special case of
that with its whitspace-dependend blocking structure that frequently causes
people confronted with it to reject python as language.

People started using higher level languages because they actually _did_
decrease the amount of problems programming caused - so the projects could
get more eleaborated.

Don't get me wrong - there is a lot of decisions to be made in language
design, and lots of them are debatable - python is no exception from that
rule. But as I said before - allowing builtins to be manipulated aks for
more trouble than its worth. Imagine a len() that always returns 1 - no
matter what you feed it. Or _if_ you're allowed to change builtin-types
constructors - then who is to decide which of the 5 different string
implementations in the various modules imported is the one to use?

The only thing you really need is a simple constructor for your undoubtly
interesting and useful string-derived class. Overloading "" as the string
constructor isn't possible - for the simple reason that only a statically
typed language could distinct the usage of the "classic" constructor vs.
your enhanced version.

So what you could do is to modify the builtins-_dict_ - that is possible -
to contain a new constructor s in it - then creating your strings is just

s('foo')

Which is only three chars more than usual string creation.

Another approach would be some macro-mechanism - but python doesn't have
such facility builtin - and I'm not aware that there is a widely adopted
3rd-party module/extenion out in the wild.

-- 
Regards,
Diez B. Roggisch


Relevant Pages

  • Re: Verbose and flexible args and kwargs syntax
    ... possible meaning for "equals" in the context of a programing language. ... That python is not the only language to not get this quite as right as ... this constructor for me', any more than **kwargs says 'please call a ... I am talking about type constraints, but as seems to be the usual ...
    (comp.lang.python)
  • Re: Scope rule pecularities
    ... >> I think it is reasonable to expect a language to behave consistently. ... >> Python does more than enought things in an implicit way. ... until we modify the string. ... So Python uses immutables as key because ...
    (comp.lang.python)
  • Re: How does Ruby compare to Python?? How good is DESIGN of Ruby compared to Python?
    ... I was considering only the language aspects of the comparison, ... through tons of stuff in the mailing lists look for examples of ... concisely as a string of method calls. ... In Python, you make a subclass of string, and over-ride ...
    (comp.lang.python)
  • Re: paul grahams arc, a new lisp, and his words about makign code ?shorter, vs forth?
    ... that exists underneath it, ... the string in the variable "sig" to the contents? ... What makes you think that Python isn't doing the same thing? ... I'm not suggesting language X is better than Y or even that Y sucks. ...
    (comp.lang.forth)
  • Re: initializing mutable class attributes
    ... I need to understand the 'WHY' behind a design ... satisfied with an explanation of "that's the Python way and you just have to ... the design of a language can make a very good language. ... default constructor and a non-default one at the same time. ...
    (comp.lang.python)