Re: Python and Ruby

2010-02-02 Thread waku
Steven D'Aprano wrote:
> On Sat, 30 Jan 2010 16:58:34 +, tanix wrote:

[...]

> > The very idea of using a number of blanks to identify your block level
> > is as insane as it gets.
>
> Not at all. People do it all the time. The very idea of expecting people
> to count nested braces to identify block level is what is crazy, which is
> why in languages with braces people still indent the blocks.

for reading written code, it's surely helpful to have the code
indented, though for *human* reading, the count of blanks seems rather
inessential, as long as intended difference in indents is more
pronounced than incidental difference between same-level lines.

for writing new code, it's not necessarily that helpful to be *forced*
to keep with strict indenting rules.  in early development phases,
code is often experimental, and parts of it may need to be blocked or
unblocked as the codebase grows, and for experimentation, the need to
carefully and consistently indent and de-indent large chunks of code
can easily lead to a mess (blame it on the programmer, not the
language, but still).  yes, there are editors that help you indent
chunks of code, but see below.

there are languages where indentation can be either enforced and allow
one to omit some syntactic nuissance like braces or begin-end clauses,
or made optional, requiring other syntactic means for delimiting
blocks etc.  (consider f# with its #light declaration, for example.)

[...]

> In any case, if your IDE mixes tabs and spaces, your IDE is broken and
> you should fix your tools rather than blame the language.

as long as you are limited to your own code, sure.  but if many work
on the same bit, and use different editors and indentation policies,
blanks-tabs indentation issues are not unlikely.  you can have blanks
converted to tabs and vice versa automatically, but that's clearly a
nuisance.


>
>
> > Braces is the most reliable way to identify blocks.
>
> Nonsense. For the compiler, both are equally reliable, and for the human
> reader, indents beat braces easily.

if blanks and tabs are mixed together as indentation, the setting of
your ide can easily mess up the indentation, making the structure
unclear.  in some editors, you can have braces highlighted, so that
it's even easier to see where a block ends or starts.  and more
advanced editors help one see the structure of the code, whereby both
indentation and braces are made less important for the reader.

but yes, indentation surely helps in reading the code.

>
>
> > Sane compilers ignore blanks altogether.
>
> Really? So a "sane compiler" sees no difference between:
>
> for x in mylist:
>
> and
>
> forxinmylist:
>
>
> I'm glad I don't have to program using a compiler you consider "sane".

the point here was, i think, that blanks may have no syntactic
meaning, though they can still be essential at the lexical level.
your example targeted the lexical level, and that's rather irrelevant
to the problem of syntactically meaningful indentation discussed here.

vQ
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Ruby

2010-02-09 Thread waku
On Feb 2, 10:49 pm, Jonathan Gardner 
wrote:
> On Feb 2, 2:21 am,waku wrote:

[...]

> > there are languages where indentation can be either enforced and allow
> > one to omit some syntactic nuissance like braces or begin-end clauses,
> > or made optional, requiring other syntactic means for delimiting
> > blocks etc.  (consider f# with its #light declaration, for example.)
>
> If you're writing "experimental code", you're doing it wrong. Every
> line of code you write may end up on the space shuttle one day (so to
> speak!) Why not write the code well-formatted in the first place, so
> that any bugs you introduce are as easily visible as possible?

you're missing the large part of the language's customers that use it
specifically for experimenting.  they're not developing space
shuttles, but rather explore available data, experiment with
algorithms, etc.  (and for space shuttles, i doubt python is the first
choice anyway.)

yes, i am writing lots of experimental code, and i know many who do,
too, and there is *nothing* wrong about it.  and then, i sometimes use
ipython to interactively experiment, saving the input to a log file,
and editing it afterwards as needed.  and just the mere fact that i
*have* to adapt my editor to ipython's indentation policy (or vice
versa) whenever working with others' code because otherwise the code
fails, is fairly annoying.  there is nothing wrong or stupid about the
editor in this respect.


> The only reason why you may want to write crap code without proper
> formatting is because your text editor is stupid.

'proper' formatting is, in some languages, something achieved by
simply running a pretty formatter.  in some, it's the job of the
programmer.  it has nothing to do with the claimed stupidity of the
editor.

> If that's the case,
> get rid of your text editor and find some tools that help you do the
> right thing the first time.

[...]

> If you're text editor has a problem with indenting, you have a
> terrible text editor. Period, end of sentence.
>

you're just wrong.


> You can't screw in bolts with a hammer, and you can't level with a
> saw.

... and you can't freely format you code with python.

> Don't try to write code in any language without a real text

'real'?  meaning one able to guess how to combine code from multiple
developers with different indentation policies, for example, one using
tabs, another four spaces, and yet another eight?  (which is not at
all uncommon, and not quite wrong or stupid.)

> editor that can do proper indentation. Don't let your teammates use
> deficient text editors either. I wouldn't appreciate it if I delivered
> precision components that my teammates tried to install with
> sledgehammers.
>
> This is the 21st Century. Good text editors are not hard to find on
> any platform.

'stupid', 'wrong', 'deficient', 'terrible', ...  you're using strong
words instead of concrete arguments, it might intimidate your
opponents, but is hardly helpful in a fair discussion.

vQ


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Ruby

2010-02-10 Thread waku
On Feb 9, 10:41 pm, Jonathan Gardner 
wrote:
> On Feb 9, 1:51 am, waku  wrote:
>
> > 'stupid', 'wrong', 'deficient', 'terrible', ...  you're using strong
> > words instead of concrete arguments, it might intimidate your
> > opponents, but is hardly helpful in a fair discussion.
>
> In today's day and age, I don't know how a text editor which cannot do
> simple indentation can be considered anything but "stupid", "wrong",
> "deficient", and "terrible". There is simply no excuse for this kind
> of behavior on the part of the text editor.

i thought we were not discussing text editors, why should you insist
so much on diverting attention from the issue of a programmer being
*forced* to keep perfect indentation to the issue of an editor doing
autoindent or the like.

>
> I mean, how long has vi had the auto indent feature? How many decades
> has emacs supported the same? This isn't new technology, or difficult
> technology to implement. It's not even non-standard anymore. Heck, far
> more advanced features, such as syntax highlighting, are standard in
> all text editors.

wow!  and then, back to the issue of enforced indentation in python?


> Your problem is you're using something like Windows Notepad to edit
> your code.

thin ice!  you haven't got the faintest idea of what i use to edit my
code, do you.


Windows Notepad is a terrible tool for writing anything,
> let alone writing code. Why in the world would any programming
> language adapt itself to the mental deficiencies of Windows Notepad? I
> mean, if you were an artist, would you use MS Paint to do anything
> serious? If you did, would you complain that the art world has a
> problem because they don't accept your paintings?
>
> I strongly suggest you download one of the *hundreds* of free text
> editors available for the Windows platform that give you the
> indentation features you so sorely lack. I suggest ViM, though it has
> a steep learning curve.

listen to what people say before responding, and stop showing off.
again, you haven't used a single reasonable argument here.

vQ

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Perl Hacker, Python Initiate

2011-02-03 Thread waku
you've already got a hint on how to do it using library functions in
python.  below is a more literal suggestion.

On Feb 1, 10:36 pm, Gary Chambers  wrote:
> All,
>
> Given the following Perl script:
>
> #!/usr/bin/perl
>
> %dig = (
>      solaris => "/usr/sbin/dig",
>      linux   => "/usr/bin/dig",
>      darwin  => "/usr/bin/dig"
> );


dig = {"solaris":"/usr/sbin/dig", "linux":"/usr/bin/dig", "darwin":"/
usr/bin/dig"}


>
> $DIG = $dig{"$^O"};

dig = dig[os.uname()[0].lower()]


> $DOMAIN = "example.com";
> $DNS = "ns.example.com";

domain, dns = ['%sexample.com'%p for p in ('', 'ns.')] # ;)

> $DIGCMD = qq/$DIG \@$DNS $DOMAIN axfr/;

digcmd = '%s @%s %s axfr' % (dig, dns, domain)

>
> open DIG, "$DIGCMD|" or die "$DIG: $!\n";
> while () {
>      next if (/^;/); # Skip any comments
>      # If we match a CNAME record, we have an alias to something.
>      # $1 = alias (CNAME), $2 = canonical hostname
>      if (/^(\S+)\.${DOMAIN}\.\s+\d+\s+IN\s*CNAME\s+(\S+)\.${DOMAIN}\.$/) {
>          # Push an alias (CNAME) onto an array indexed on canonical hostname
>          push(@{$cnames{$2}}, $1);
>      }
>      # Here's a standard A (canonical hostname) record
>      # $1 = canonical hostname, $2 = IPv4 address
>      if (/^(\S+)\.${DOMAIN}\.\s+\d+\s+IN\s*A\s+(\S+)$/) {
>          $ip{$1} = $2;
>      }}
>
> close DIG;

lines = [line for line in os.popen(digcmd) if not re.match(';', line)]
cname, ip = [re.compile(s.format(domain))
for s in (r'(\S+)\.{0}\.\s+\d+\s+IN\s*CNAME\s+(\S+)\.{0}\.$', r'(\S
+)\.{0}\.\s+\d+\s+IN\s*A\s+(\S+)$')]
cnames, ips = [dict(m.groups() for m in (p.match(l) for l in lines) if
m) for p in cname, ip)]

the rest is left as an exercise.  i did not test this exact code
because i don't have your data, but a modified version works on
different data.

vQ

>
> # Format and display it like niscat hosts:
> # canonicalHostname alias1 [alias2 aliasN] ipAddress
> for $host (sort keys %ip) {
>      print "$host ";
>      if (defined(@{$cnames{$host}})) {
>          print join(' ', @{$cnames{$host}});
>          print " ";
>      }
>      print "$ip{$host}\n";}
>
> exit 0;
>
> Will someone please provide some insight on how to accomplish that task in
> Python?  I am unable to continually (i.e. it stops after displaying a single
> line) loop through the output while testing for the matches on the two
> regular expressions.  Thank you.
>
> -- Gary Chambers

-- 
http://mail.python.org/mailman/listinfo/python-list