Suggested coding style

P

Petite Abeille

I am looking for the python mailing list. . ? Have you guys seen it
somewhere? I think I accidently reached the cry-me-a-river list?

The portal can be reactivated by intoning Bobby Brown Goes Down in unison.
 
W

Westley Martínez

I'm kind of new to the whole mailing list thing, but they seem to be a
lot more lenient than internet forums about most things. I've noticed
that sometimes Off-topic posts can get a little out of hand. I guess
it's not really a big deal, but it bothers me, and the trolls just love
to feed on it. I mean, as programmers, we should devote our time to
improving computer systems. On this mailing list, we're programmers,
nothing else, and so we shouldn't mingle other things into the list.
Think of it as using global variables or even a goto. That's
essentially what OT is. It just serves to obfuscate valuable answers to
good programming questions.
 
C

Chris Angelico

On this mailing list, we're programmers,
nothing else, and so we shouldn't mingle other things into the list.
Think of it as using global variables or even a goto.  That's
essentially what OT is.

Not a bad analogy, that... but I accept it in perhaps not the same way
as you intended it.

I don't mind using a global variable once in a while. I don't object
to a well-placed goto, especially when it's clear and obvious what
it's doing. And the occasional off-topic post or thread on a mailing
list isn't the end of the world either.

ChrisA
 
I

Ian Kelly

A specific method for padding a string with ONLY zeros is ludicrous
and exposes the narrow mindedness of the creator. The only thing worse
than "zfill" as a string method is making zfill into built-in
function! The ONLY proper place for zfill is as an option in the
str.format() method.

py> "{0:zf10}".format(1234) -> "00000000001234"

Agree that zfill seems to be redundant with str.format, although your
suggested syntax is atrocious, especially since a syntax already
exists that fits better in the already-complicated format specifier
syntax.

"{0:=010d}".format(1234) -> "0000001234"

There are a couple of warts with the existing implementation, however:

1) str.zfill() operates on strings; the .format() syntax operates on
numeric types. I would suggest that the "=" fill alignment in format
specifiers should be extended to do the same thing as zfill when given
a string.

2) It seems to not behave as documented for floats. I expect:

"{0:=010f}".format(-32.7) -> "-0000032.7"

I get:

"{0:=010f}".format(-32.7) -> "-32.700000"

On the other hand, I can't imagine why I would ever actually want the
expected result, so maybe it's not a big deal.
 
C

Chris Rebert

I'm kind of new to the whole mailing list thing, but they seem to be a
lot more lenient than internet forums about most things.  I've noticed
that sometimes Off-topic posts can get a little out of hand.  I guess
it's not really a big deal, but it bothers me, and the trolls just love
to feed on it.  I mean, as programmers, we should devote our time to
improving computer systems.

This is why good mail clients have a "Mute" or equivalent function to
ignore an entire thread and not let it waste any more of your time.

You may want to plonk Xah and the ranter who goes by Rick while you're at it. :)

Cheers,
Chris
 
R

rantingrick

Agree that zfill seems to be redundant with str.format, although your
suggested syntax is atrocious, especially since a syntax already
exists that fits better in the already-complicated format specifier
syntax.

It's interesting that you find the format specifier "complicated". I
will admit that upon first glance i lamented the new format method
spec and attempted to cling to the old string interpolation crap.
However, as you use the new format method you will come to appreciate
it. It's an adult beverage with an acquired taste. ;-)

One thing that may help format noobs is to look at the spec as two
parts; the part before the colon and the part after the colon. If you
break it down in this manner the meaning starts to shine through. I
will agree, it is a lot of cryptic info squeezed into a small space
HOWEVER you would no want a verbose format specification.

But i wholeheartedly agree with you points and i would say the zfill
method has no future uses in the stdlib except for historical reasons.
We should deprecate it now.

"{0:=010d}".format(1234) -> "0000001234"

There are a couple of warts with the existing implementation, however:

1) str.zfill() operates on strings; the .format() syntax operates on
numeric types.  I would suggest that the "=" fill alignment in format
specifiers should be extended to do the same thing as zfill when given
a string.

EXACTLY!

PS: Has anyone noticed all the off topic chatter about religion and
feelings? Since the main subject of this thread is about zfill i can't
help but wonder if the minions where sent out to present a distraction
with "scripted" pseudo arguments. Just an observation.
 
D

Devin Jeanpierre

There we disagree. The hurt feelings of someone who attaches their identity
to a text should not restrain our discourse.

Yes, we do.
That would eliminate just about every joke: a huge range of jokes *depend*
for their humour on connecting seemingly-unrelated ideas. So by your logic,
we don't get to make those jokes here.

I didn't have much logic. I just don't think it's nice to do things
that hurt other people, and if we can, we should avoid those things.
Avoiding them is pretty easy here.
But whoever takes that joke and says it's deliberately hurtful is being
presumptuous and censorious and unreasonable. If they then castigate the
joker for supposedly hurting someone's feelings, it's at that point the
atmosphere turns hostile to discussion.

I don't really care about the "joke". I honestly I didn't understand
it as a joke, which would drive most of my disagrement. I don't think
it should have been made, yes. I take major issue with the
anti-Christian rant that appeared afterward, but I haven't really
taken much opportunity to attack it because it doesn't matter. All I'd
like is for people to be a little more friendly, if you please.

I also didn't reprimand anyone, except maybe Steven.

But anyway, no, we don't agree on what it means to be friendly or what
a hostile atmosphere is. I've noticed that people tend to be a lot
harsher here than what I'm used to, so perhaps your attitude to it is
more common on mailing-lists and I should just adapt.

Devin
 
D

Devin Jeanpierre

However, as you use the new format method you will come to appreciate
it. It's an adult beverage with an acquired taste. ;-)

Yeah. It's a much more difficult to read thing, but once you learn how
to write it it flows faster.

Of course, I never managed to learn how to write it...

I would suggest that rather than being "complicated" it is "dense".
PS: Has anyone noticed all the off topic chatter about religion and
feelings? Since the main subject of this thread is about zfill i can't
help but wonder if the minions where sent out to present a distraction
with "scripted" pseudo arguments. Just an observation.

May I suggest a email client that can group mailing list threads?
Also, not accusing others of conspiracies.

Devin
 
C

Chris Angelico

But anyway, no, we don't agree on what it means to be friendly or what
a hostile atmosphere is. I've noticed that people tend to be a lot
harsher here than what I'm used to, so perhaps your attitude to it is
more common on mailing-lists and I should just adapt.

I'm told that there are other mailing lists / newsgroups that are far,
FAR more hostile than this. Haven't explored though, as I don't feel
like torturing myself :)

As to the original offensiveness, though: I'm a fundamentalist
Christian (not Catholic though), and I water-off-a-duck's-backed the
insult. If it's true, it's allowed to be offensive; if it's not true,
I can distance myself from it. (In this case, the latter; the inner
issues of the Catholic church are unconnected to the core of
Christianity.)

Chris Angelico
 
E

Ethan Furman

Ben said:
But whoever takes that joke and says it's deliberately hurtful is being
presumptuous and censorious and unreasonable. If they then castigate the
joker for supposedly hurting someone's feelings, it's at that point the
atmosphere turns hostile to discussion.

Um, wasn't it RantingRick who made this 'joke'? Do you honestly believe
he /wasn't/ trying to be offensive?

~Ethan~
 
M

MRAB

Um, wasn't it RantingRick who made this 'joke'? Do you honestly believe
he /wasn't/ trying to be offensive?
rantingrick:
"""Since, like the bible the zen is self contradicting, any argument
utilizing
the zen can be defeated utilizing the zen."""

alex23:
"""And like the Bible, the Zen was created by humans as a joke. If you're
taking it too seriously, that's your problem."""
 
E

Ethan Furman

Ethan said:
Um, wasn't it RantingRick who made this 'joke'? Do you honestly believe
he /wasn't/ trying to be offensive?

Okay, that's what I get for skimming -- it was alex23, not rr. My
apologies, rr, for the misattribution.

~Ethan~
 
R

rantingrick

Yeah. It's a much more difficult to read thing, but once you learn how
to write it it flows faster.

Of course, I never managed to learn how to write it...

A good way to start out is to just use the positional arguments.

py> name = "Bob"

py> "Hello my name is {0}".format(name)
Hello my name is Bob

py> "Hello my name is {name}".format(name=name)
Hello my name is Bob

py> "Hello my name is {0}. My named spelled backwards is:
{0}".format(name)
Hello my name is Bob. My named spelled backwards is: Bob

py> "A small fry cost {0:0.2f}".format(1.6666666)
A small fry cost 1.67

py> "A small car cost {0:,.2f}".format(11666.6666)
A small car cost 11,666.67

# Python 2.7+ you can omit the index.
py> "{} = {}".format("value",2)
value = 2

Start with the small stuff and then diversify! You'll be glad you made
the change.
 
R

rantingrick

Agree that zfill seems to be redundant with str.format, although your
suggested syntax is atrocious, especially since a syntax already
exists that fits better in the already-complicated format specifier
syntax.

"{0:=010d}".format(1234) -> "0000001234"

There are a couple of warts with the existing implementation, however:

1) str.zfill() operates on strings; the .format() syntax operates on
numeric types.  I would suggest that the "=" fill alignment in format
specifiers should be extended to do the same thing as zfill when given
a string.

Ah ha! Found the answer!

py> "{0:010d}".format(1234)
0000001234

py> "{0:0>10}".format(1234)
0000001234

py> "{0:0>10}".format("1234")
0000001234

py> "{0:mad:>10}".format("1234")
@@@@@@1234

I would skip using the "{int}{repeat}d" syntax and just use the string
padding since you won't need to worry about the input data type. I
hate specificity types in string formats. With the old interpolation i
ALWAYS used %s for everything.
 
R

rantingrick

Okay, that's what I get for skimming -- it was alex23, not rr.  My
apologies, rr, for the misattribution.

Oh don't worry Ethan, this is not the first time I've been falsely
accused, misquoted, and kicked in the testicles, and i'm quite sure
with this fine group of folks it won't be the last either.
 
C

Chris Angelico

Speak for yourself.

I don't think he meant that the populace here is exclusively
programmers, but that *on this list* we are here because we're
programmers. We may happen to have coincidental interest in (say)
music, but just because some group of us (or even all of us) all enjoy
music does not mean that it'd be on-topic to have a discussion of the
tetrachord of Mercury.

ChrisA
 
A

alex23

What is so bad about breaking code in obscure places?

Try coding in PHP across minor release versions and see how you feel
about deprecating core functions on a whim.
We changed print
to a function which broke just about every piece of code every written
in this language.

In a well declared _break_ with backwards compatibility. Not on a whim
between minor releases.
(BTW, print should ALWAYS have been a function!)

Unfortunately, not everyone is as infallible as you. Or as
intractable. Coding styles change over time: this is a concept known
as "progress", although it's not as obvious in monocultures, so you
may not have heard of it.
What is so bad then about breaking some very obscure code?

Because while you say "some very obscure code", what you really mean
is "code that isn't mine".
GvR should be texting me every night in hopes that some of my API genius will rub
off on him.

Are you off your medication again?
I believe GvR had a "mid-dev-crisis"[...]

You seem to believe a lot of absolute garbage. As you have no access
to the inner states of _any_ of the people you regularly condemn here
with your hypocritical attacks, I've no idea why you consider yourself
to be an expert on their desires and opinions.
 

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,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top