Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #39952

Re: Do you feel bad because of the Python docs?

References <512cb0a0$0$30001$c3e8da3$5496439d@news.astraweb.com> <mailman.2541.1361884843.2939.python-list@python.org> <roy-DB6F9D.08561526022013@news.panix.com>
Date 2013-02-27 01:26 +1100
Subject Re: Do you feel bad because of the Python docs?
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2546.1361888810.2939.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, Feb 27, 2013 at 12:56 AM, Roy Smith <roy@panix.com> wrote:
> When people ask PHP questions, the questions tend to be phrased as "what
> do I type to get X", and the answers come back that way too.  The forums
> are full of, "I had the same problem.  Somebody told me to do this.  I
> don't really understand it, but it worked for me and maybe it'll work
> for you too".

A problem that's majorly exacerbated by the myriad ways of doing some
things, with some of those ways deprecated and others theoretically
plausible but hopelessly impractical.

Here's an actual example that came up today at work. Suppose you have
a user-provided string that's supposed to contain a URL, and you need
to ensure that it doesn't have a trailing slash, so you can later add
"/foo" or "/bar". (Or alternatively, ensure that it DOES have a
trailing slash. Either works.) Start the timer, go find out how to do
it. Assume you are broadly familiar with PHP, and know how to do the
basics of string handling, and are competent at searching the web.
Ready? Go!

I'll wait for you to come back.

... Okay, some of you are back now. Just giving the stragglers time to
finish losing their marbles...

Alright. Here's what I found in a recreation of today's search.
Google search: php last character of string

http://php.net/manual/en/function.substr.php
-- okay, so I can use substr, but not string indexing, to find out
what the last character is
-- "Returns the extracted part of string; or FALSE on failure, or an
empty string." What kind of failures result in FALSE, and what kind in
an empty string?

http://stackoverflow.com/questions/4427172/find-last-character-in-a-string-in-php
Comment on question: "There are more than 10 ways of doing this!"
The accepted answer, fortunately, is a good one. Use rtrim. Okay.
That's nice. But look at the other answers: one mentions substr (as
above, that's half the question); one suggests the unwieldy form of
indexing from the back (with an explicit strlen); one answers
altogether the wrong question (suggesting the use of basename); and
one... suggests a regular expression. Now you have two problems.

And just to add to the pile of ways this could be done, the first
response in this thread
https://forums.digitalpoint.com/threads/how-to-get-last-character-in-string.796134/
suggests *reversing the string* and indexing from the front.

Maybe you tried different search terms and got better results, I don't
know. This wasn't the only search I did in trying to find the best way
to do this, but it was the one with the most amusing results.

The original rant specifically excluded sites like Stack Overflow as
valid sources, which in a way is fair enough. But it wasn't from
php.net that I got that information.

Okay. Now I'll try it again, for Python.
Google search: python last character of string
First result:
3.1.2 Strings
docs.python.org/release/1.5.1p1/tut/strings.html
Besides numbers, Python can also manipulate strings, which can be
expressed ... word[-1] # The last character 'A' >>> word[-2] # The
last-but-one character 'p' ...

The use of code with directly connected comments means that I can read
this part of the solution right there, without even clicking the link.
Search Engine Optimization FTW.

Searching for the second part, by adding the word 'remove' to the
search, brings up more third-party sites - for PHP:
http://www.if-not-true-then-false.com/2010/php-remove-last-character-from-string/
and for Python:
https://groups.google.com/forum/?fromgroups#!topic/comp.lang.python/TIX5u3Zhikc
http://stackoverflow.com/questions/9639754/python-remove-last-char-from-string-and-return-it

In both cases, answering the question, but not from the language's own
site. Forcing the matter with a site: search brings up poor results
for both languages. Python gives me:
http://docs.python.org/release/2.6/library/string.html
but nothing about slicing. PHP: Take your pick of functions, and I
hope you already know what they do, because the snippets don't help
you choose:
substr, rtrim, chop (which, once you go to the page, reveals itself to
be an alias for rtrim), strrpos, substr_replace, strstr

I'd have to say that, in the shoot-out, both languages died on their
own merits, but stood on the merits of third-party support. Fifteen
years ago, I would have called that a critical failure; in the 90s, I
would search for information only from official sources. But these
days, forum archives and blogs are some of the best way to find what
you need - granted, Sturgeon's Law applies, but frankly that applies
to a lot of documentation too (and Google's fairly good at helping you
find the 10%).

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Do you feel bad because of the Python docs? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-26 12:54 +0000
  Re: Do you feel bad because of the Python docs? Chris Angelico <rosuav@gmail.com> - 2013-02-27 00:20 +1100
    Re: Do you feel bad because of the Python docs? Roy Smith <roy@panix.com> - 2013-02-26 08:56 -0500
      Re: Do you feel bad because of the Python docs? Chris Angelico <rosuav@gmail.com> - 2013-02-27 01:26 +1100
        Re: Do you feel bad because of the Python docs? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-26 15:26 +0000
      Re: Do you feel bad because of the Python docs? MRAB <python@mrabarnett.plus.com> - 2013-02-26 17:48 +0000
        Re: Do you feel bad because of the Python docs? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-27 03:02 +0000
  Re: Do you feel bad because of the Python docs? Zero Piraeus <schesis@gmail.com> - 2013-02-26 10:15 -0400
  Re: Do you feel bad because of the Python docs? Devin Jeanpierre <jeanpierreda@gmail.com> - 2013-02-26 09:15 -0500
  Re: Do you feel bad because of the Python docs? notbob <notbob@nothome.com> - 2013-02-26 16:19 +0000
    Re: Do you feel bad because of the Python docs? Andrew Berg <bahamutzero8825@gmail.com> - 2013-02-26 10:55 -0600
      Re: Do you feel bad because of the Python docs? notbob <notbob@nothome.com> - 2013-02-26 17:54 +0000
        Re: Do you feel bad because of the Python docs? Tim Chase <python.list@tim.thechases.com> - 2013-02-26 12:10 -0600
          Re: Do you feel bad because of the Python docs? notbob <notbob@nothome.com> - 2013-02-26 18:41 +0000
    Re: Do you feel bad because of the Python docs? nn <pruebauno@latinmail.com> - 2013-02-26 11:00 -0800
      Re: Do you feel bad because of the Python docs? emile <emile@fenx.com> - 2013-02-26 16:36 -0800
  Re: Do you feel bad because of the Python docs? "Adam W." <AWasilenko@gmail.com> - 2013-02-26 08:38 -0800
    Re: Do you feel bad because of the Python docs? Devin Jeanpierre <jeanpierreda@gmail.com> - 2013-02-26 13:52 -0500
    Re: Do you feel bad because of the Python docs? Terry Reedy <tjreedy@udel.edu> - 2013-02-26 20:48 -0500
      Re: Do you feel bad because of the Python docs? Rick Johnson <rantingrickjohnson@gmail.com> - 2013-02-26 19:13 -0800
        Re: Do you feel bad because of the Python docs? alex23 <wuwei23@gmail.com> - 2013-02-27 15:25 -0800
          Re: Do you feel bad because of the Python docs? Rick Johnson <rantingrickjohnson@gmail.com> - 2013-02-27 18:05 -0800
            Re: Do you feel bad because of the Python docs? Roy Smith <roy@panix.com> - 2013-02-27 21:21 -0500
            Re: Do you feel bad because of the Python docs? Chris Angelico <rosuav@gmail.com> - 2013-02-28 13:44 +1100
              Re: Do you feel bad because of the Python docs? Rick Johnson <rantingrickjohnson@gmail.com> - 2013-02-27 19:43 -0800
                Re: Do you feel bad because of the Python docs? llanitedave <llanitedave@veawb.coop> - 2013-02-27 20:04 -0800
                Re: Do you feel bad because of the Python docs? alex23 <wuwei23@gmail.com> - 2013-02-27 20:21 -0800
            Re: Do you feel bad because of the Python docs? alex23 <wuwei23@gmail.com> - 2013-02-27 20:18 -0800
              Re: Do you feel bad because of the Python docs? Rick Johnson <rantingrickjohnson@gmail.com> - 2013-02-27 20:53 -0800
                Re: Do you feel bad because of the Python docs? alex23 <wuwei23@gmail.com> - 2013-02-27 21:57 -0800
                Re: Do you feel bad because of the Python docs? Chris Angelico <rosuav@gmail.com> - 2013-02-28 17:31 +1100
                Re: Do you feel bad because of the Python docs? Rick Johnson <rantingrickjohnson@gmail.com> - 2013-02-28 10:28 -0800
                Re: Do you feel bad because of the Python docs? Chris Angelico <rosuav@gmail.com> - 2013-03-01 07:41 +1100
                Re: Do you feel bad because of the Python docs? alex23 <wuwei23@gmail.com> - 2013-02-28 16:05 -0800
                Re: Do you feel bad because of the Python docs? Jake Angulo <jake.angulo@gmail.com> - 2013-03-04 10:47 +1100
          Re: Do you feel bad because of the Python docs? Bob Hanson <invalid@invalid.invalid> - 2013-03-05 17:43 -0800
            Re: Do you feel bad because of the Python docs? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-03-06 03:12 +0000
              Re: Do you feel bad because of the Python docs? Bob Hanson <invalid@invalid.invalid> - 2013-03-08 19:10 -0800
          Re: Do you feel bad because of the Python docs? Bob Hanson <invalid@invalid.invalid> - 2013-03-05 17:50 -0800
          Re: Do you feel bad because of the Python docs? Bob Hanson <invalid@invalid.invalid> - 2013-03-05 17:51 -0800
            Re: Do you feel bad because of the Python docs? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-06 03:38 +0000
              Re: Do you feel bad because of the Python docs? Bob Hanson <invalid@invalid.invalid> - 2013-03-08 19:31 -0800
                Re: Do you feel bad because of the Python docs? Chris Angelico <rosuav@gmail.com> - 2013-03-09 14:45 +1100
            Re: Do you feel bad because of the Python docs? rh <richard_hubbe11@lavabit.com> - 2013-03-06 11:48 -0800
            Re: Do you feel bad because of the Python docs? Terry Reedy <tjreedy@udel.edu> - 2013-03-06 18:50 -0500
              Re: Do you feel bad because of the Python docs? Rick Johnson <rantingrickjohnson@gmail.com> - 2013-03-06 16:47 -0800
                Re: Do you feel bad because of the Python docs? alex23 <wuwei23@gmail.com> - 2013-03-06 17:06 -0800
                Re: Do you feel bad because of the Python docs? Chris Kaynor <ckaynor@zindagigames.com> - 2013-03-06 17:28 -0800
                Re: Do you feel bad because of the Python docs? Rick Johnson <rantingrickjohnson@gmail.com> - 2013-03-06 17:31 -0800
                Re: Do you feel bad because of the Python docs? alex23 <wuwei23@gmail.com> - 2013-03-06 18:28 -0800
                Re: Do you feel bad because of the Python docs? Rick Johnson <rantingrickjohnson@gmail.com> - 2013-03-06 18:57 -0800
                Re: Do you feel bad because of the Python docs? alex23 <wuwei23@gmail.com> - 2013-03-06 19:12 -0800
                Re: Do you feel bad because of the Python docs? Rick Johnson <rantingrickjohnson@gmail.com> - 2013-03-06 19:48 -0800
                Re: Do you feel bad because of the Python docs? Chris Angelico <rosuav@gmail.com> - 2013-03-07 13:16 +1100
                Re: Do you feel bad because of the Python docs? "Michael Ross" <gmx@ross.cx> - 2013-03-07 03:04 +0100
                Re: Do you feel bad because of the Python docs? Terry Reedy <tjreedy@udel.edu> - 2013-03-06 20:52 -0500
                Re: Do you feel bad because of the Python docs? Rick Johnson <rantingrickjohnson@gmail.com> - 2013-03-06 18:41 -0800
              Re: Do you feel bad because of the Python docs? Bob Hanson <invalid@invalid.invalid> - 2013-03-08 20:12 -0800
                Re: Do you feel bad because of the Python docs? Terry Reedy <tjreedy@udel.edu> - 2013-03-09 01:22 -0500
        Re: Do you feel bad because of the Python docs? Roy Smith <roy@panix.com> - 2013-02-27 20:26 -0500
  Re: Do you feel bad because of the Python docs? Terry Reedy <tjreedy@udel.edu> - 2013-02-26 13:43 -0500
    Re: Do you feel bad because of the Python docs? rurpy@yahoo.com - 2013-02-27 17:17 -0800
      Re: Do you feel bad because of the Python docs? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-02-28 01:39 +0000
      Re: Do you feel bad because of the Python docs? Terry Reedy <tjreedy@udel.edu> - 2013-02-27 21:27 -0500
  Re: Do you feel bad because of the Python docs? Mitya Sirenef <msirenef@lightbird.net> - 2013-02-26 13:58 -0500
  Re: Do you feel bad because of the Python docs? rh <richard_hubbe11@lavabit.com> - 2013-02-26 12:18 -0800
  Re: Do you feel bad because of the Python docs? Rotwang <sg552@hotmail.co.uk> - 2013-02-26 21:26 +0000
    Re: Do you feel bad because of the Python docs? Jason Swails <jason.swails@gmail.com> - 2013-02-26 17:17 -0500
      Re: Do you feel bad because of the Python docs? Rick Johnson <rantingrickjohnson@gmail.com> - 2013-02-26 17:22 -0800
      Re: Do you feel bad because of the Python docs? Rick Johnson <rantingrickjohnson@gmail.com> - 2013-02-26 17:22 -0800
  Re: Do you feel bad because of the Python docs? Mark Janssen <dreamingforward@gmail.com> - 2013-02-26 17:15 -0800
  Re: Do you feel bad because of the Python docs? Chris Angelico <rosuav@gmail.com> - 2013-02-27 12:31 +1100
  Re: Do you feel bad because of the Python docs? Terry Reedy <tjreedy@udel.edu> - 2013-02-26 21:00 -0500
  Re: Do you feel bad because of the Python docs? rh <richard_hubbe11@lavabit.com> - 2013-02-26 18:06 -0800
  Re: Do you feel bad because of the Python docs? Mitya Sirenef <msirenef@lightbird.net> - 2013-02-26 22:09 -0500
  Re: Do you feel bad because of the Python docs? Mitya Sirenef <msirenef@lightbird.net> - 2013-02-26 23:45 -0500
  Re: Do you feel bad because of the Python docs? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-02-27 09:47 +0000
  Re: Do you feel bad because of the Python docs? Antoine Pitrou <solipsis@pitrou.net> - 2013-02-27 13:17 +0000
  Re: Do you feel bad because of the Python docs? Antoine Pitrou <solipsis@pitrou.net> - 2013-02-27 13:22 +0000
    Re: Do you feel bad because of the Python docs? Rick Johnson <rantingrickjohnson@gmail.com> - 2013-02-27 14:59 -0800
  Re: Do you feel bad because of the Python docs? Mitya Sirenef <msirenef@lightbird.net> - 2013-02-27 17:43 -0500
  Re: Do you feel bad because of the Python docs? rurpy@yahoo.com - 2013-02-27 15:20 -0800
    Re: Do you feel bad because of the Python docs? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-28 01:05 +0000
      Re: Do you feel bad because of the Python docs? rurpy@yahoo.com - 2013-02-27 21:36 -0800
  Re: Do you feel bad because of the Python docs? llanitedave <llanitedave@veawb.coop> - 2013-02-27 18:26 -0800
  Re: Do you feel bad because of the Python docs? Jason Friedman <jsf80238@gmail.com> - 2013-02-27 21:59 -0700
  Re: Do you feel bad because of the Python docs? Chris Angelico <rosuav@gmail.com> - 2013-02-28 16:21 +1100
  Re: Do you feel bad because of the Python docs? << No! Tony the Tiger <tony@tiger.invalid> - 2013-03-03 16:28 -0600
  Re: Do you feel bad because of the Python docs? rh <richard_hubbe11@lavabit.com> - 2013-03-04 08:59 -0800

csiph-web