Coding standard: Prefixing variables to indicate datatype

Thomas Weholt 2002 at weholt.org
Thu Jan 16 10:28:42 CET 2003


Hm ... I see your point. I began thinking about this when I read some old
code where a variable changed datatype during its lifespan inside a function
several times. I think it was passed as a string, turned into a int and
could be returned from the function as None depending on its content. It was
awful. It was probably the worst code I've ever written, in any language,
but only Python allowed me to do it this way. If I'd prefixed the variable
to indicate it's datatype it would have been harder to change its datatype
that way, but then again --- changing datatype of a variable during
processing is probably not a very good idea in the first place.

Anyway, thanks for your input.

Thomas



"Max M" <maxm at mxm.dk> wrote in message news:3E267821.5030209 at mxm.dk...
> Thomas Weholt wrote:
> > In my day-job I use Delphi/Object Pascal. My firm has a coding-standard
> > where we prefix all variables with a single character to indicate
datatype;
> > strings are prefixed with s, integers with i, floats with f etc. etc.
> >
> > Are there any standards like this for Python? Or hints, tips, opinions
> > related to this topic?
>
>
> Yes there are: Dont! ;-)
>
> def adder(ia, ib):
>      return ia + ib
>
> print adder(40,2)
>  >>> 42
>
> print adder('40', '2')
>  >>> 402
>
> You cannot be shure what type a variable will be bound to.
>
> You cannot even be shure that it will stay that type, and then you will
> either have to rename them in you entire codebase, or have misleading
names.
>
> regards Max M
>
> --
>
> hilsen/regards Max M
>
> http://www.futureport.dk/
> Fremtiden, videnskab, skeptiscisme og transhumanisme
>






More information about the Python-list mailing list