Python was designed (was Re: Multi-threading in Python vs Java)

M

Metallicow

On Mon, 21 Oct 2013 01:43:52 -0700, Peter Cacioppi wrote:

Challenge: give some examples of things which you can do in Python, but
cannot do *at all* in C, C++, C#, Java?

Ummm... hmmm.... let me try here...

string = 'Python is the Best!'

if string:
try:
string = int(string)
except Exception as exc:
integer = str(integer)
else:
print('Typecasting Maybe...')

I get more comments on "Typecasting" from those who don't know how to use a press more than anything, than I get from the typesetter.
#... maybe she's ignoring me...

Am I right?
 
W

wxjmfauth

Le mardi 15 octobre 2013 23:00:29 UTC+2, Mark Lawrence a écrit :
Le lundi 14 octobre 2013 21:18:59 UTC+2, John Nagle a écrit :
No, Python went through the usual design screwups. Look at how

painful the slow transition to Unicode was, from just "str" to

Unicode strings, ASCII strings, byte strings, byte arrays,

16 and 31 bit character builds, and finally automatic switching

between rune widths. [...]
Yes, a real disaster.
This "poor" Python is spending its time in reencoding
when necessary, without counting the fact it's necessary to
check if reencoding is needed.

Where is Unicode? Away.

Use one of the coding schemes endorsed by Unicode.

If a dev is not able to see a non ascii char may use 10
bytes more than an ascii char or a dev is not able to
see there may be a regression of a factor 1, 2, 3, 5 or
more simply by using non ascii char, I really do not see
now I can help.

Neither I can force people to understand unicode.

I recieved a ton a private emails, even from core
devs, and as one wrote, this has not been seriously
tested. Even today on the misc. lists some people
are suggesting to write to add more tests.

All the tools I'm aware of, are using unicode very
smoothly (even "utf-8 tools"), Python not.

That's the status. This FSR fails. Period.

jmf
 
P

Peter Cacioppi

On Mon, 21 Oct 2013 01:43:52 -0700, Peter Cacioppi wrote:

Challenge: give some examples of things which you can do in Python, but
cannot do *at all* in C, C++, C#, Java?

Please. No exceptions is huge. No garbage collection is huge.

But you can do anything with a Turing machine. You can do anything in assembly. The point is to pick the appropriate tool for the job.

I can build a house without a nail gun. I can probably even build a house without a hammer. But it's a waste of time to build things with the wrong tools.
 
S

Steven D'Aprano

As I personally know nothing about unicode for the unenlightened such as
myself please explain this statement with respect to the fsr.

Please don't encourage JMF. You know he'll just continue with his
ridiculous vendetta against Python 3.3's Unicode handling.

Are you saying that an ascii char takes a byte but a non ascii char
takes up to 11?

He's talking about the fact that strings in Python are objects, and hence
carry a certain amount of overhead. Just to prove it's not specific to
Python 3.3, or Unicode, here's an empty byte-string in 2.6:

py> sys.getsizeof('')
24

On the other hand, this overhead becomes trivial as the string gets
bigger:

py> sys.getsizeof('x'*10**6)
1000024


Unicode is no different. Here is the hated 3.3 again:

py> sys.getsizeof('') # Unicode, not byte-string
25
py> sys.getsizeof('ó'*10**6)
1000037


Again, a totally trivial amount of overhead. If you aren't willing to pay
that overhead for the convenience of an OOP language like Python, you
shouldn't be using an OOP language like Python.
 
S

Steven D'Aprano

Please. No exceptions is huge. No garbage collection is huge.

You have over-trimmed and lost context. The context here is that I
maintain that one of the reasons for inventing new languages is to
provide useful programming idioms and techniques in a convenient, clean
way, that is, with syntactic support and a minimum of needless
boilerplate. You have objected to this view, and (if I understand you
correctly) believe that there are certain idioms which are *impossible*
in C, hence the invention of new languages.

I agree with you that garbage collection and exceptions are useful,
powerful features. I agree with you that the difference between a
language which supports them natively (like Python) and one which does
not (like C) is huge. But beyond that I think you are mistaken.

C does not natively provide garbage collection, or exceptions, or many
other features. But that doesn't make it *impossible* to use these
features in C, it just makes them *inconvenient and difficult*. To get
the advantage of such features, you have to build a framework that
provides them, then exclusively use the framework, while avoiding
dropping down into the underlying low-level C features that bypass the
framework. This is inconvenient, error-prone, inelegant, and requires
discipline, but it is *possible*.

Take the framework to the next level: add custom syntax, a parser, and a
system for translating your custom syntax to (say) C, or machine code for
some (real or virtual) machine. We call this *a programming language*.
But that's just an incremental step beyond a framework, which in turn is
just an incremental step beyond a library, which in turn is just an
incremental step beyond an ad hoc system of useful wrapper functions and
conventions.

In a very real sense, Python is "just" a convenience wrapper around a
bunch of C functions to provide OOP idioms, garbage collection, dynamic
typing, runtime introspection, exceptions, and similar.

But you can do anything with a Turing machine. You can do anything in
assembly. The point is to pick the appropriate tool for the job.

I agree! And building those tools is one of the reasons why people create
new programming languages: to make useful techniques and idioms easier to
use.

I can build a house without a nail gun. I can probably even build a
house without a hammer. But it's a waste of time to build things with
the wrong tools.

I don't think the right analogy is with the nail gun versus hammer. Both
result in the same finished product: two pieces of timber joined together
with one or more pointy bits of steel. Sure, a nail gun is faster and
easier, but the idiom is the same.

A better analogy is to consider the various ways to assemble timber:
nails, screws, glue, dowels, biscuits, dovetail joints, etc. These are
all *idioms and techniques* for getting the same result (two pieces of
wood joined), rather than different tools for performing the same idiom
(drive a nail using a nail gun, a hammer or a rock). Each idiom has
different pros and cons: biscuits are good for joining chipwood edge-to-
edge, but lousy for load bearing structural timbers.

Like all analogies, it doesn't pay to take it too far, but essentially
you can think of a language like Python as being like a machine shop with
a dedicated biscuit joiner, while C is like one without such a device.
You can use the same technique in both, but the ease of use, convenience
and reliability is quite different:

* In Python, you use the biscuit joiner to quickly cut out a matching,
nicely machined slot in both pieces of chipboard.

* In C, you have to manually and carefully drill out many thin holes in
the chipboard, then laboriously cut through to make a slot, then file
smooth by hand. Not only is this much more work, but the end result is
likely to be less reliable.


For anyone who has no idea what I'm talking about when I talk about
biscuit joiners:


http://en.wikipedia.org/wiki/Biscuit_joiner
 
C

Chris Angelico

C does not natively provide garbage collection, or exceptions, or many
other features. But that doesn't make it *impossible* to use these
features in C, it just makes them *inconvenient and difficult*. To get
the advantage of such features, you have to build a framework that
provides them, then exclusively use the framework, while avoiding
dropping down into the underlying low-level C features that bypass the
framework. This is inconvenient, error-prone, inelegant, and requires
discipline, but it is *possible*.

Provably possible, by the Sir Ruthven method[1]: libnih, as used by
Upstart and other systems, is a garbage-collected (refcounted, I
think) C memory allocation library. I believe I mentioned this earlier
in one of these threads.
For anyone who has no idea what I'm talking about when I talk about
biscuit joiners:

http://en.wikipedia.org/wiki/Biscuit_joiner

As one of the "anyone", I thank you :)

ChrisA

[1] See Ruddigore, where Sir Ruthven claims to have forged his own
will; his uncle claims it's not possible, which Sir R disproves by
saying that he's already done so.
 
P

Peter Cacioppi

Steven said -
"In a very real sense, Python is "just" a convenience wrapper around a
bunch of C functions to provide OOP idioms, garbage collection, dynamic
typing, runtime introspection, exceptions, and similar. "


I can't really disagree with you in a factual sense, but somehow it doesn'treally convey the right flavor.

The success or failure of a project (or an entire company) can rest on the correct choice of programming language. Whether you failed because you werepursuing an impossible task or merely a very, very, very hard one is sort of semantics, and cold comfort to the those affected.

Maybe I'm biased because I'm walking away from a six figure job coding Javaand C for a large company to write Python for a tiny non-profit.
 
P

Paul Rubin

Peter Cacioppi said:
Please. No exceptions is huge. No garbage collection is huge.
But you can do anything with a Turing machine. ...

Lumping C, C++, C#, and Java together misses the most important thing.
Python, C#, and Java all have a vital capability, that's inherently
missing from C and C++, and it's not garbage collection. Namely, you
get the ability to write a program and have the assurance that bugs in
your code won't overwrite memory at random or make the program segfault.
You instead get a reasonable stack trace saying what was going on when
the error happened.

To riff on Benjamin Pierce, programming is not just about letting you
supply the presence of given behaviors (any sane Turing-complete
language lets you do that). It's also about ensuring the -absence- of
other behaviors, and that in fact is where the heavy lifting of language
design is mostly directed.

FYI, there is real though imprecise garbage collection for C. Web
search for "Boehm garbage collection" should find more info.
 
P

Peter Cacioppi

Paul Rubin said:

"FYI, there is real though imprecise garbage collection for C. Web
search for "Boehm garbage collection" should find more info"

Very interesting. This wasn't around the last time I launched a C/C++ project from scratch. Thanks for the tip.

I have to admit, off the top of my head I can't quite grok how it could possibly work .... which means I will learn something from studying it. But not right now.

Thanks! Some great CS minds on this forum.
 
M

Mark Lawrence

Paul Rubin said:

"FYI, there is real though imprecise garbage collection for C. Web
search for "Boehm garbage collection" should find more info"

Very interesting. This wasn't around the last time I launched a C/C++ project from scratch. Thanks for the tip.

I have to admit, off the top of my head I can't quite grok how it could possibly work .... which means I will learn something from studying it. But not right now.

Thanks! Some great CS minds on this forum.

Very true.

Now before I forget I hope you find these links useful.

http://dirtsimple.org/2004/12/python-is-not-java.html
http://dirtsimple.org/2004/12/java-is-not-python-either.html
 

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
474,093
Messages
2,570,607
Members
47,227
Latest member
bluerose1

Latest Threads

Top