Ahik Man | 1 Jul 13:48 2010
Picon

Python coding question

What do you think about this code:
for n in range(2, 10): ... for x in range(2, n): ... if n % x == 0: ... print n, 'equals', x, '*', n/x ... break ... else: ... # loop fell through without finding a factor ... print n, 'is a prime number'

I don't like this 'for - else' trick. IMHO it's confusing and not readable.

BTW, This code is taken from the python tutorial:
_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
Amit Aronovitch | 1 Jul 14:28 2010
Picon

Re: [pyweb-il:1050] Python coding question

 

On Thu, Jul 1, 2010 at 2:48 PM, Ahik Man <ahik.man <at> gmail.com> wrote:
What do you think about this code:
for n in range(2, 10): ... for x in range(2, n): ... if n % x == 0: ... print n, 'equals', x, '*', n/x ... break ... else: ... # loop fell through without finding a factor ... print n, 'is a prime number'

I don't like this 'for - else' trick. IMHO it's confusing and not readable.


‎I really like this (very natural) programmatial construct.
I use it all the time, and feel handicapped in languages such as C, where you have to define an extra boolean flag and manually set/check it to achieve the same result.

  As for the choice of keywords, it is not that bad (maybe just got used to it after years of usage), but I agree the semantics might not be obvious to unaware readers. Certainly not up to Python's praised readability standards.
  Personally, I don't like the choice of '=' as the syntactical marker for name-binding. It makes people think it is an operator, and expect c-like semantics. Source of endless bugs for newbies and repeated misunderstandings in mailing lists.

 Well, the advantage of having a BDFL is that someone is in charge of making such choices and we do not have to argue about this any more. Only other option is to try to keep everyone happy by supporting several versions of the syntax (works fine in Perl, but takes its toll in readability and/or learning-curve).

   AA

_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
Ron Reiter | 1 Jul 13:51 2010
Picon

Re: [pyweb-il:1049] Python coding question

They should have used another keyword.
I guess it's too late now :)

On Thu, Jul 1, 2010 at 2:48 PM, Ahik Man <ahik.man <at> gmail.com> wrote:
What do you think about this code:
for n in range(2, 10): ... for x in range(2, n): ... if n % x == 0: ... print n, 'equals', x, '*', n/x ... break ... else: ... # loop fell through without finding a factor ... print n, 'is a prime number'

I don't like this 'for - else' trick. IMHO it's confusing and not readable.

BTW, This code is taken from the python tutorial:

--
You received this message because you are subscribed to the Google Groups "PyWeb-IL" group.
To post to this group, send email to pyweb-il <at> googlegroups.com.
To unsubscribe from this group, send email to pyweb-il+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pyweb-il?hl=en.



--
-- Ron
_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
Shai Berger | 1 Jul 14:41 2010

Re: [pyweb-il:1050] Python coding question

Ahik, you're not alone; 

http://groups.google.com/group/comp.lang.python/browse_thread/thread/502f0b9c5a8cf795/2c52451a016d6aac

But as Amit says, it does help in many cases.
_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
Dov Grobgeld | 1 Jul 16:35 2010
Picon

Re: [pyweb-il:1050] Python coding question

The use of assigment through left arrow (←) would solve this. Which reminds me of the fact that I would have loved having a language like python that uses more of unicode for its syntax.

Then "python" might look like:

    ∀ n ∈ names:
      if n ≠ "foo":
        α ← n
        ß = re∘search⟨"foo", α⟩

No more overloading of parens, decimal dots, minus signs, etc.

Of course it would take some time to learn how to type all these chars on the keyboard, but by some clever editors macro tricks, you would quickly get over this.

Here's another pythonic construct that imo would look nicer.

    f← λ x: x↑2
    a
←f⟨2⟩

But I'm dreaming. Nobody will ever do anything as crazy as this...

Cheers,
Dov

On Thu, Jul 1, 2010 at 15:28, Amit Aronovitch <aronovitch <at> gmail.com> wrote:
 

On Thu, Jul 1, 2010 at 2:48 PM, Ahik Man <ahik.man <at> gmail.com> wrote:
What do you think about this code:
for n in range(2, 10): ... for x in range(2, n): ... if n % x == 0: ... print n, 'equals', x, '*', n/x ... break ... else: ... # loop fell through without finding a factor ... print n, 'is a prime number'

I don't like this 'for - else' trick. IMHO it's confusing and not readable.


‎I really like this (very natural) programmatial construct.
I use it all the time, and feel handicapped in languages such as C, where you have to define an extra boolean flag and manually set/check it to achieve the same result.

  As for the choice of keywords, it is not that bad (maybe just got used to it after years of usage), but I agree the semantics might not be obvious to unaware readers. Certainly not up to Python's praised readability standards.
  Personally, I don't like the choice of '=' as the syntactical marker for name-binding. It makes people think it is an operator, and expect c-like semantics. Source of endless bugs for newbies and repeated misunderstandings in mailing lists.

 Well, the advantage of having a BDFL is that someone is in charge of making such choices and we do not have to argue about this any more. Only other option is to try to keep everyone happy by supporting several versions of the syntax (works fine in Perl, but takes its toll in readability and/or learning-curve).

   AA


_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il


_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
cool-RR | 1 Jul 16:39 2010

Re: [pyweb-il:1050] Python coding question

Wow, this is pretty cool.

For what it's worth, Mathematica does a bit of this. (But it's not really like Python.)

On Thu, Jul 1, 2010 at 4:35 PM, Dov Grobgeld <dov.grobgeld <at> gmail.com> wrote:
The use of assigment through left arrow (←) would solve this. Which reminds me of the fact that I would have loved having a language like python that uses more of unicode for its syntax.

Then "python" might look like:

    ∀ n ∈ names:
      if n ≠ "foo":
        α ← n
        ß = re∘search⟨"foo", α⟩

No more overloading of parens, decimal dots, minus signs, etc.

Of course it would take some time to learn how to type all these chars on the keyboard, but by some clever editors macro tricks, you would quickly get over this.

Here's another pythonic construct that imo would look nicer.

    f← λ x: x↑2
    a
←f⟨2⟩

But I'm dreaming. Nobody will ever do anything as crazy as this...

Cheers,
Dov

On Thu, Jul 1, 2010 at 15:28, Amit Aronovitch <aronovitch <at> gmail.com> wrote:
 

On Thu, Jul 1, 2010 at 2:48 PM, Ahik Man <ahik.man <at> gmail.com> wrote:
What do you think about this code:
for n in range(2, 10): ... for x in range(2, n): ... if n % x == 0: ... print n, 'equals', x, '*', n/x ... break ... else: ... # loop fell through without finding a factor ... print n, 'is a prime number'

I don't like this 'for - else' trick. IMHO it's confusing and not readable.


‎I really like this (very natural) programmatial construct.
I use it all the time, and feel handicapped in languages such as C, where you have to define an extra boolean flag and manually set/check it to achieve the same result.

  As for the choice of keywords, it is not that bad (maybe just got used to it after years of usage), but I agree the semantics might not be obvious to unaware readers. Certainly not up to Python's praised readability standards.
  Personally, I don't like the choice of '=' as the syntactical marker for name-binding. It makes people think it is an operator, and expect c-like semantics. Source of endless bugs for newbies and repeated misunderstandings in mailing lists.

 Well, the advantage of having a BDFL is that someone is in charge of making such choices and we do not have to argue about this any more. Only other option is to try to keep everyone happy by supporting several versions of the syntax (works fine in Perl, but takes its toll in readability and/or learning-curve).

   AA


_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il



_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il




--
Sincerely,
Ram Rachum
_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
Shai Berger | 1 Jul 16:52 2010

Re: [pyweb-il:1050] Python coding question


On Thursday 01 July 2010 17:35:20 Dov Grobgeld wrote:
> The use of assigment through left arrow (←) would solve this. Which reminds
> me of the fact that I would have loved having a language like python that
> uses more of unicode for its syntax.
> 
> Then "python" might look like:
> 
>     ∀ n ∈ names:
>       if n ≠ "foo":
>         α ← n
>         ß = re∘search〈"foo", α〉
> 
> No more overloading of parens, decimal dots, minus signs, etc.
> 

Look up fortress at http://projectfortress.sun.com/, specifically 
http://projectfortress.sun.com/Projects/Community/wiki/MathSyntaxInFortress

It's not exactly what you asked for, but it's damned close.

Have fun,
	Shai.
_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
guy keren | 1 Jul 16:57 2010
Picon
Picon

Re: [pyweb-il:1050] Python coding question


next you'll be advocating special keyboards with extra keys for these 
symbols.

what do you want to turn us into, IBM mainframe APL programmers?

--guy

Dov Grobgeld wrote:
> The use of assigment through left arrow (←) would solve this. Which 
> reminds me of the fact that I would have loved having a language like 
> python that uses more of unicode for its syntax.
> 
> Then "python" might look like:
> 
>     ∀ n ∈ names:
>       if n ≠ "foo":
>         α ← n
>         ß = re∘search〈"foo", α〉
> 
> No more overloading of parens, decimal dots, minus signs, etc.
> 
> Of course it would take some time to learn how to type all these chars 
> on the keyboard, but by some clever editors macro tricks, you would 
> quickly get over this.
> 
> Here's another pythonic construct that imo would look nicer.
> 
>     f← λ x: x↑2
>     a←f〈2〉
> 
> But I'm dreaming. Nobody will ever do anything as crazy as this... ☺
> 
> Cheers,
> Dov
> 
> On Thu, Jul 1, 2010 at 15:28, Amit Aronovitch <aronovitch <at> gmail.com 
> <mailto:aronovitch <at> gmail.com>> wrote:
> 
>      
> 
> 
>         On Thu, Jul 1, 2010 at 2:48 PM, Ahik Man <ahik.man <at> gmail.com
>         <mailto:ahik.man <at> gmail.com>> wrote:
> 
>             What do you think about this code:
> 
>             for n in range(2, 10):
>             ...     for x in range(2, n):
>             ...         if n % x == 0:
>             ...             print n, 'equals', x, '*', n/x
>             ...             break
>             ...     else:
>             ...         # loop fell through without finding a factor
>             ...         print n, 'is a prime number'
> 
> 
>             I don't like this 'for - else' trick. IMHO it's confusing
>             and not readable.
> 
> 
>     ‎I really like this (very natural) programmatial construct.
>     I use it all the time, and feel handicapped in languages such as C,
>     where you have to define an extra boolean flag and manually
>     set/check it to achieve the same result.
> 
>       As for the choice of keywords, it is not that bad (maybe just got
>     used to it after years of usage), but I agree the semantics might
>     not be obvious to unaware readers. Certainly not up to Python's
>     praised readability standards.
>       Personally, I don't like the choice of '=' as the syntactical
>     marker for name-binding. It makes people think it is an operator,
>     and expect c-like semantics. Source of endless bugs for newbies and
>     repeated misunderstandings in mailing lists.
> 
>      Well, the advantage of having a BDFL is that someone is in charge
>     of making such choices and we do not have to argue about this any
>     more. Only other option is to try to keep everyone happy by
>     supporting several versions of the syntax (works fine in Perl, but
>     takes its toll in readability and/or learning-curve).
> 
>        AA
> 
> 
>     _______________________________________________
>     Python-il mailing list
>     Python-il <at> hamakor.org.il <mailto:Python-il <at> hamakor.org.il>
>     http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Python-il mailing list
> Python-il <at> hamakor.org.il
> http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il

_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
Dov Grobgeld | 1 Jul 18:08 2010
Picon

Re: [pyweb-il:1050] Python coding question

Didn't know about Fortress, but it is still not the same as it is a post process rendering of the program through TeX, but it is not the input to the interpreter. Donal Knuth's program weave is a similar approach. But both these approaches are for printing, not for editing.

Regarding APL. Though it makes interesting use of alternate symbols, the language itself is not what I want. Just compare the languages J and Python. They are both written in ASCII, but that's where the similarities end.

Regarding keyboard input. I don't care the least what it sais on my keyboard keytops. (I'm using Dvorak). If you can type Chinese on a keyboard, then you should be able to type any math symbol as well.

Cheers,
Dov

On Thu, Jul 1, 2010 at 17:52, Shai Berger <shai <at> platonix.com> wrote:

On Thursday 01 July 2010 17:35:20 Dov Grobgeld wrote:
> The use of assigment through left arrow (←) would solve this. Which reminds
> me of the fact that I would have loved having a language like python that
> uses more of unicode for its syntax.
>
> Then "python" might look like:
>
>     ∀ n ∈ names:
>       if n ≠ "foo":
>         α ← n
>         ß = re∘search⟨"foo", α⟩
>
> No more overloading of parens, decimal dots, minus signs, etc.
>

Look up fortress at http://projectfortress.sun.com/, specifically
http://projectfortress.sun.com/Projects/Community/wiki/MathSyntaxInFortress

It's not exactly what you asked for, but it's damned close.

Have fun,
       Shai.

_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
cool-RR | 4 Jul 13:32 2010

הרצאה על גארליקסים - פלפטורמה פייתונית לסימולציות מחשב

אהלן!

(למי שכבר קיבל הודעה על ההרצאות האלה דרך רשימות תפוצה אחרות, אני מצטער על הכפילות; אתם יכולים להתעלם מההודעה הזאת.)

קוראים לי רם רחום. אני מפתח בפייתון, ואני הולך לתת הרצאות על פרוייקט קוד-פתוח שאני מפתח בפייתון, שנקרא GarlicSim. זה האתר של הפרוייקט:


גארליקסים זאת פלטורפמה פייתונית לסימולציות מחשב. לא ארחיב כאן בדיבור, אתם מוזמנים להיכנס לאתר כדי ללמוד על זה עוד.

אני הולך לתת שתי הרצאות על גארליקסים, בשני מיקומים שונים. ההרצאות פתוחות לקהל הרחב ללא תשלום.


בחיפה, אני הולך לתת הרצאה מחר, יום שני 5.7.2010, בשעה 18:30 בכיתה טאוב 6 בטכניון. זאת במסגרת מועדון Haifux. הוראות הגעה.

ברמת-גן, אני הולך לתת הרצאה ביום חמישי, ה-22 ביולי, בשעה 19:00, במכללת שנקר, רחוב אנה פרנק 12, חדר 300. זאת במסגרת מועדון TelFOSS. הוראות הגעה.


מצפה לראותכם,
רם.
_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il

Gmane