login
Holden Web
What you'll need to know tomorrow

Comments on What Matters About Python?, page 2 of 2

Re: What Matters About Python?

James Watson · 2007-08-16T10:56:00

> > I hope not. Hadn't even thought of that. That would be,
> > well, not good.
>
> It does not:

Oops. I missed the point. Sorry. It actually looks like it does.

Re: What Matters About Python?

Elizabeth Wiethoff · 2007-08-16T13:40:00

I don't know what an "average reader" is looking for, but I'll mention something almost trivial that this out-of-the-average reader really appreciates about Python: "the whitespace thing."

My vision is lousy. Hence, I work with huge fonts and screen real estate is at a premium. The fact that whitespace delimits Python blocks means I don't have to waste a line typing "end" (as in Ruby) or "}" (as in several Algol family languages). Typing, of course, is not the problem, but reading is. Without those silly delimiters, I can see more lines of executable code in my editor and hold less code in my head.

Re: What Matters About Python?

Merriodoc Brandybuck · 2007-08-16T14:52:00

> > Merriodoc, sorry to be a code pedant, but...
> >
> > [x.lower() for x in linesSource if x.lower() not
> in
> > map(string.lower, linesTarget)]

> >
> > Will that execute map(string.lower, linesTarget) once
> per
> > line in linesSource? If so... yuck!
> >
>
> I hope not. Hadn't even thought of that. That would be,
> well, not good.
>
>
> > Here's what I would do in Ruby (I can't find the Python
> > function for list subtraction, and the - operator
> doesn't
> > seem to work):
> >
> > linesSource.map{|x|x.downcase} -
> > linesTarget.map{|x|x.downcase}

>
> There isn't a list subtraction function or operator I'm
> aware of. Mathematically speaking, that is treating an
> array like a set (with the exception that duplicates are
> allowed) and if you want to do something like that, you
> can use the set data type in python
>
>
> >>> a = set(['a','b','c'])
> >>> b = set(['a','f','x'])
> >>> a - b
> set(['c', 'b'])
> >>>
>


Hopefully to put an end to the code pedantics, not that I mind them :-)


set(map(string.lower, linesSource)) - set(map(string.lower, linesTarget))


lower is mapped only once to each array and set allows you the pretty use of the '-' operator.

I used to cringe a little at the whitespace thing. Now I just don't care. Almost everybody I know who cringes ends up not caring. But, I think, that topic has gotten beaten to death. The only syntax flakiness that I even think about sometimes is that trailing ':' after if statements, for loops, etc.

Re: What Matters About Python?

James Watson · 2007-08-17T07:36:00

> I used to cringe a little at the whitespace thing. Now I
> just don't care. Almost everybody I know who cringes ends
> up not caring. But, I think, that topic has gotten beaten
> to death. The only syntax flakiness that I even think
> about sometimes is that trailing ':' after if statements,
> for loops, etc.

I think Elizabeth was in favor of the 'whitespace thing'. I too find it odd that this is considered by many to be a deficiency in Python because I think it's great. At first, I was a little skeptical but when I realized that I can't stand when people don't indent properly, I reconsidered.

I would even like to use this idea to create a simplified form of XML equivalent documents. When I've suggested this in the past, people have claimed that whitespace is 'dangerous' because it's too easy to change.

Has anyone ever had this occur to them in Python where reformatting the code changing the meaning? It seems kind of like a theoretical problem.

Re: What Matters About Python?

Merriodoc Brandybuck · 2007-08-17T19:01:00

Advertisement
> > I used to cringe a little at the whitespace thing. Now
> I
> > just don't care. Almost everybody I know who cringes
> ends
> > up not caring. But, I think, that topic has gotten
> beaten
> > to death. The only syntax flakiness that I even think
> > about sometimes is that trailing ':' after if
> statements,
> > for loops, etc.
>
> I think Elizabeth was in favor of the 'whitespace thing'.
> I too find it odd that this is considered by many to be a
> a deficiency in Python because I think it's great. At
> first, I was a little skeptical but when I realized that I
> can't stand when people don't indent properly, I
> reconsidered.
>

I believe she was, too. I just found it interesting because so many people complain about it. Indent properly is subjective in just about every other language. It can be maddening when other people's version of 'proper' does not match your own :-)


> I would even like to use this idea to create a simplified
> form of XML equivalent documents. When I've suggested
> this in the past, people have claimed that whitespace is
> 'dangerous' because it's too easy to change.
>

I don't think easy to change is the issue. Easy to confuse tabs and spaces is what causes problems. All text is easy to change. whitespace is annoying because it is hard to see.

> Has anyone ever had this occur to them in Python where
> reformatting the code changing the meaning? It seems kind
> of like a theoretical problem.

The only issue I've had with whitespace is in moving from one editor to another loading old code where tabs are used instead of spaces. emacs untabify is a lifesaver in cases like this. But then, the meaning doesn't really change, the code just doesn't run.

Re: What Matters About Python?

James Watson · 2007-08-20T06:33:00

> > > I used to cringe a little at the whitespace thing.
> Now
> > I
> > > just don't care. Almost everybody I know who cringes
> > ends
> > > up not caring. But, I think, that topic has gotten
> > beaten
> > > to death. The only syntax flakiness that I even think
> > > about sometimes is that trailing ':' after if
> > statements,
> > > for loops, etc.
> >
> > I think Elizabeth was in favor of the 'whitespace
> thing'.
> > I too find it odd that this is considered by many to be
> a
> > a deficiency in Python because I think it's great. At
> > first, I was a little skeptical but when I realized that
> I
> > can't stand when people don't indent properly, I
> > reconsidered.
> >
>
> I believe she was, too. I just found it interesting
> because so many people complain about it. Indent properly
> is subjective in just about every other language. It can
> be maddening when other people's version of 'proper' does
> not match your own :-)

What I mean is inconsistently or in confusing ways. I've seen code like this:
if (a) blah;
  if (b) blah;
     if (c) blah;

Or where nested ifs were not indented compared to their parents. I've seen just plain random indentation.

Code formatters help with this but can make it hard to track changes in source control, if not done carefully. Mostly, I annoys me that people can be so sloppy. It's no surprise I find so many bugs in this kind of code.

Re: What Matters About Python?

Merriodoc Brandybuck · 2007-08-20T06:45:00

> What I mean is inconsistently or in confusing ways. I've
> seen code like this:
>
> if (a) blah;
>   if (b) blah;
>      if (c) blah;
> 

> Or where nested ifs were not indented compared to their
> parents. I've seen just plain random indentation.
>
> Code formatters help with this but can make it hard to
> track changes in source control, if not done carefully.
> Mostly, I annoys me that people can be so sloppy. It's
> s no surprise I find so many bugs in this kind of code.

wow, that would make me cranky, too.

Re: What Matters About Python?

ian o · 2007-08-20T22:49:00

>>What are the warts, and what have you found Python to be especially good or bad for?

Warts? As another poster already noted- the complexity of distributing python apps is problematic. Not only is the interpreter not always present by default, but anyone wanting to distibute apps to end users as pyc code has to worry about which verion or generate the cryptic 'bad magic number' messages. (why can't installations deal with prior version pycs?)

Good for....web apps where the app resides on the server and distribution is not an issue :)

Re: What Matters About Python?

Steve Holden · 2007-10-03T18:55:00

Thank you all for your contributions. I have been heavily occupied elsewhere since writing the post (and have already written a couple of pieces for the magazine, editorial schedules being what they are), but this gives me a huge vein of interesting stuff.

The pieces I have done so far have mostly been opinion. I will, in response to clear demand, be trying to ensure from now on that every piece includes at least a little code.

Older comments · Page 2 of 2

Back to post