the lvalue curse? let's play with this crazy idea ;)

X

XLiIV

I started playing with Python and love it since the very beginning,
programming using Python is so ...human-like? but one thing returns to
me almost everytime when I see/write the code


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 ;)


<almost code>
time.time() -> ftime -> time.localtime() -> p -> p[:3] -> g -> list(g)
-> '-'.join()
</almost code>

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? :)

I realize that there is no chance to implement it, but I really want
to share it :]

Peace,
T.

PS
forgive my my english
[shall I set it as a signature? ;) ]
 
M

Marc 'BlackJack' Rintsch

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
 
B

Bruno Desthuilliers

XLiIV a écrit :
I started playing with Python and love it since the very beginning,
programming using Python is so ...human-like? but one thing returns to
me almost everytime when I see/write the code


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])

You don't need the call to list here.
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 ;)


<almost code>
time.time() -> ftime -> time.localtime() -> p -> p[:3] -> g -> list(g)
-> '-'.join()
</almost code>

print "-".join(map(str, localtime(time.time())[:3]))

or

print "-".join(str[item] for item in localtime(time.time())[:3])

My example conclusion and not-ansewered-yet question...
-it's nice to read

Very subjective point here. I'm afraid I don't share your POV.
and choosing the good names to variables aren't so
important
-what is the purpose of the variables here? :)

help debugging ? make code easier to grasp ?
I realize that there is no chance to implement it,

In Python ? Not a chance, indeed.
 
X

XLiIV

Maybe it's also harder to read than this::

  print '-'.join(map(str, time.localtime()[:3]))

I like this concept, it's so, .. ziped :)
Of course, if you don't mind the extra padding zeroes in day and month::

  print time.strftime('%Y-%m-%d')

I'll be humble, it covers my need the most :)
If you have a lack of knowladge you work harder...
One instruction (besides 'print')... . Do you believe it? :)

You are a little bit inconsistent with the arguments.  `g` is explicitly
mentioned in ``list(g)``.  But why the intermediate names at all?

That's right, because it was just a scratch of an idea..
The point of the idea was this...
I read from left to right, and because of that it's easier to me
follow this way of writing (you only follow by one direction and the
value is handing over, from left to rigght ...):

value -> do_something -> result -> action_on_the_result -> ...

than this multiline lvalues assignes

variable = value # I take a look at the left then the right
result = do_something(variable) # Here I check also left and right
side, and perhaps I (a short memory) may check the line over
action_on_the_result(result)
...

However, I've just found out, that even the more difficult method to
me isn't so scary if I read it like this
...
6 7
4 5
2 3
1
However the 2nd:
because there is:
print '-'.join(map(str, time.localtime()[:3]))

so i'm not serious convincing anyone :)

Maybe you should look into languages like SmallTalk or Io where everything
is done with method calls.  Your example in Io::

I took a brief look at them, and Python is still Nr OnE :)
 
T

Terry Reedy

Pipelining works best when all functions have just one input.
But that is a small subset of actual programs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top