the lvalue curse? let's play with this crazy idea ;)
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Fri May 9 05:52:03 EDT 2008
On Fri, 09 May 2008 02:13:34 -0700, XLiIV wrote:
> Let's take a look at two ways of thinking...
> the standard one which is well-known and loved by almost everyone :)
> and that crazy concept below which suprised evan me :wacko:
>
> <code>
> import time
>
> ftime = time.time()
> localtime = time.localtime(ftime)
> localtime = list(localtime[:3])
> localtime = [str(i) for i in localtime]
> print '-'.join(localtime)
> </code>
>
> It's harder to read than the below concept, isn't?
> Maybe I didn't used to this way of thinking yet. I hope it'll change
> soon or i'll quit ;)
Maybe it's also harder to read than this::
print '-'.join(map(str, time.localtime()[:3]))
Of course, if you don't mind the extra padding zeroes in day and month::
print time.strftime('%Y-%m-%d')
> <almost code>
> time.time() -> ftime -> time.localtime() -> p -> p[:3] -> g -> list(g)
> -> '-'.join()
> </almost code>
You are a little bit inconsistent with the arguments. `g` is explicitly
mentioned in ``list(g)``. But why the intermediate names at all?
> My example conclusion and not-ansewered-yet question...
> -it's nice to read and choosing the good names to variables aren't so
> important
> -what is the purpose of the variables here? :)
Exactly. But look at my snippet above: No intermediate names either.
> I realize that there is no chance to implement it, but I really want
> to share it :]
Maybe you should look into languages like SmallTalk or Io where everything
is done with method calls. Your example in Io::
Date now do("#{year}-#{month}-#{day}" interpolate linePrint)
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list