Mark,
Thanks for the expansion.
Yes, there are ever more ways to format text.
There can be an indefinite expansion beyond this is many ways.
I was thinking of ways to make bits and pieces from objects and stringing them
together, perhaps inventing your own methods.
Anyone can come up with another meta-language, perhaps embed them in a module
with classes, and use overloading methods to make it easier to use.
But worst of all is to simply find an external application and open up a
connection to it such as with Popen() or a call to a URL that accepts some
formatting string and returns something formatted.
Consider something like a UNIX Shell language like sh/csh/ksh or more modern
incarnations like BASH that use a dollar sign in imaginative ways such as $PATH
or `command args` to make substitutions. You can imagine invoking something
like that while passing along parts needed and taking back the result.
Now, arguably, those are not part of the language. But if you want to build a
weird enough scenario, you could have a Rube Goldberg device that bounced
around multiple servers on the internet running many kinds of OS and percolated
some complex result back into a now formatted string.
Diversity is nice but also often a distraction. Worse is when trying to read
what others have written. On that topic, I note many people like to include
short segments in their ENGLISH writing from other languages. Latin and French
are common inserts as they are easy to read albeit not always to comprehend.
Lawyers seem unable to communicate without lots of Latin nonsense and some
musicians must toss in periodic tidbits of Italian and so on. Languages that
use characters totally outside what is in the character sets In English or near
relatives that have added characters with diacritical marks, are less often
seen. How often do you see Greek or Hebrew? OK, I admit I see them often, but
my reading tastes are eclectic. I bet many would at least like a translation
and/or transliteration next to such quotes or just the translation.
Back to programming. Nothing wrong with multiple ways if they offer more
functionality that is useful
But why constantly reinvent the wheel as an ellipse? Look at the issue of
strings. There actually is a reason for the many variation in python. Single
and double quotes are pretty much identical with the exception that they make
it easier to include the other symbol without backslashes. Triple quotes (three
doubles) offer other improvements and so do several raw or Unicode variants.
But strictly speaking, they are often more syntactic sugar for one or a few
underlying storage mechanisms accompanied by access methods. Objects, of a
sort. The f version mentioned as a formatting method is in a sense another such
object with additional methods. You can well imagine more such things you can
design into a language, albeit some may not be able to use existing symbols you
ran out of unless you want to use "'"'" stuff "'"'" (where you may not be able
to read the nested " and ' and " and ' and " to have some exotic meaning like
format the sting repeatedly in a loop till it does not change. For example, if
$PATH evaluated to
something${DATE}something`echo "hello \$world!"`something
and $DATE expanded to $MONTH/$DAY/$YEAR
then repeated formatting till no more expansions happen could be another type
of string. No, not asking for that especially since I can see easy ways to make
infinite loops 😊
Mark, perhaps jokingly, asks what can you do for your language. Nice sentiment
but I find it less useful to be wedded or loyal to things as it is always more
interesting to see if something new developed is at least as interesting. Many
ideas when carried through to the point of absurdity stop being as useful. I am
thinking of some LISP variants with very nice mathematical/philosophical ideas
including how an amazing number of things can be done recursively. So if you
asked them to write a function in lisp that compares A and B, they don't bother
putting the numbers in two registers like A and B and issuing a compare
directive at machine language level. Instead, they write the LISP equivalent of
this pseudocode:
Greater(A,B)
If A == 0, return FALSE
If B == 0, return TRUE
Otherwise, return Greater(A-1, B-1)
Try comparing A,B = 999,999,999,999, 1,000,000,000,000
How much memory does your computer have? The numbers are ONE apart with A being
smaller. But the algorithm slavishly puts recursive function calls on the stack
about a trillion times then unwinds. You say no problem, tail recursion allows
replacing the function on the stack. Maybe. So all you need is a trillion times
the CPU time or so for something done in a few cycles in most hardware.
(((((Parenthetically, I am not picking on LISP), as most modern) (computer
languages)) allow (((equivalent)) code. )))
Half the fun when I thought LISP was having people get lost counting
parentheses at a time that editors did not easily tell you what matched what.
But keeping track of multiple threads in a GUI can be a modern version of
nested complexity.
I used to observe the Obfuscated C contests years ago. Anyone for obfuscated
python. Well, not here in the tutor group.
https://www.ioccc.org/
http://wiki.c2.com/?ObfuscatedPython
I have played in the past with tricks to write code mostly in a language like
Hungarian using a pre-processor that flipped the key words back into the usual
English style and of course used variable names in yet other languages like
transliterated Aramaic. Hard to find people who could even figure out what the
program did. Throw that into a language like Python where you can create
classes and overload operators and it can get to look like an Abbot and
Costello routine.
But if you want clear, self-documenting, code, I prefer that.
Time to get back to normal questions on this forum?
-----Original Message-----
From: Tutor <[email protected]> On Behalf Of Mark
Lawrence
Sent: Tuesday, November 20, 2018 3:45 PM
To: [email protected]
Subject: Re: [Tutor] Pythonic way
On 20/11/2018 18:08, Avi Gross wrote:
>
> We have two completely separate ways to format strings that end up
> with fairly similar functionality. Actually, there is an implicit
> third way 😊
>
You could argue five ways :-)
1. C printf style formatting
https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting
2. New style string formatting
https://docs.python.org/3/library/string.html#string-formatting
3. f-strings
https://docs.python.org/3/reference/lexical_analysis.html#f-strings
4. String templates
https://docs.python.org/3/library/string.html#template-strings
5. String methods
https://docs.python.org/3/library/stdtypes.html#string-methods
Any advance on five anybody?
--
My fellow Pythonistas, ask not what our language can do for you, ask what you
can do for our language.
Mark Lawrence
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor