OSDev.org

The Place to Start for Operating System Developers
It is currently Mon Sep 23, 2019 5:28 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 35 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: Why do I despise python
PostPosted: Wed May 17, 2017 10:48 pm 
Offline
Member
Member

Joined: Wed Nov 18, 2015 3:04 pm
Posts: 350
Location: San Jose San Francisco Bay Area
It has been source of all trouble:

Reason 1.
Code:
>>> a = 1
>>> b = a
>>> a
1
>>> b
1
>>> a = 100
>>> a
100
>>> b
1
>>>
>>>
>>> list1 = []
>>> list1.append(100)
>>> list2 = list1
>>> list1
[100]
>>> list2
[100]
>>> list1.append(101)
>>> list1
[100, 101]
>>> list2
[100, 101]
>>>



Reason 2. When I ask technical question on python forum (first one that comes up on google search), no one can answer, just try this to see if it works, bunch of guesswork. Most of advices don't work.

_________________
key takeaway after spending yrs on sw industry: big issue small because everyone jumps on it and fixes it. small issue is big since everyone ignores and it causes catastrophy later. #devilisinthedetails


Top
 Profile  
 
 Post subject: Re: Why do I despise python
PostPosted: Wed May 17, 2017 11:56 pm 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 3466
Location: Chichester, UK
So, don't use Python.


Top
 Profile  
 
 Post subject: Re: Why do I despise python
PostPosted: Thu May 18, 2017 12:15 am 
Offline
Member
Member

Joined: Tue Mar 04, 2014 5:27 am
Posts: 976
ggodw000 wrote:
It has been source of all trouble:

Reason 1.
...


It will turn up when googling something like top Python pitfalls.
Perhaps, you just need to learn the language better if you need to use it.


Top
 Profile  
 
 Post subject: Re: Why do I despise python
PostPosted: Thu May 18, 2017 12:42 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7412
Location: Germany
Value vs. Reference. Not much of a problem in a language that makes these kind of things explicit, but somewhat of a bummer in languages that want to be "hip" and "better" and hide the differences so they look "cleaner" but really aren't.

That's why I like sticking to the older languages. They're ugly and they admit it. And the people in the forums can tell you how things work, and why they work the way they do. There's honesty in that.

_________________
Every good solution is obvious once you've found it.


Top
 Profile  
 
 Post subject: Re: Why do I despise python
PostPosted: Thu May 18, 2017 3:13 am 
Offline
Member
Member
User avatar

Joined: Tue Aug 02, 2016 1:52 pm
Posts: 286
Location: East Riding of Yorkshire, UK
Image

You can find a lot of similar complaints about JavaScript too.

_________________
com.sun.java.swing.plaf.nimbus.InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneMaximizeButtonWindowNotFocusedState
Compiler Development Forum


Top
 Profile  
 
 Post subject: Re: Why do I despise python
PostPosted: Thu May 18, 2017 4:39 am 
Offline
Member
Member

Joined: Sat Mar 15, 2014 3:49 pm
Posts: 96
Solar wrote:
Value vs. Reference. Not much of a problem in a language that makes these kind of things explicit, but somewhat of a bummer in languages that want to be "hip" and "better" and hide the differences so they look "cleaner" but really aren't.

That's why I like sticking to the older languages. They're ugly and they admit it. And the people in the forums can tell you how things work, and why they work the way they do. There's honesty in that.


C:
Code:
int a = 1;
int b = a;
a = 100;

... b is still 1;

And likewise still C:
Code:
char* list1 = calloc(3);
list1[0] = 100;
char* list2 = list1;
list1[1] = 101;


So just which old languages are you sticking with?


Top
 Profile  
 
 Post subject: Re: Why do I despise python
PostPosted: Thu May 18, 2017 5:14 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7412
Location: Germany
willedwards wrote:
Code:
char* list1 = calloc(3);
list1[0] = 100;
char* list2 = list1;
list1[1] = 101;


So just which old languages are you sticking with?


Well, are list1 and list2 clearly declared as pointers (references), or are they not?

Or C++:

Code:
std::vector<int> a;
a.push_back( 100 );
std::vector<int> b = a;
std::vector<int> * c = &a;
a.push_back( 101 );         // b = { 100 }, c = { 100, 101 }

_________________
Every good solution is obvious once you've found it.


Top
 Profile  
 
 Post subject: Re: Why do I despise python
PostPosted: Thu May 18, 2017 5:20 am 
Offline
Member
Member
User avatar

Joined: Thu Jul 12, 2012 7:29 am
Posts: 722
Location: Tallinn, Estonia
Thread should've been called "Why do I despise programmers who don't know programming languages"

_________________
Learn to read.


Top
 Profile  
 
 Post subject: Re: Why do I despise python
PostPosted: Thu May 18, 2017 5:26 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7412
Location: Germany
Basically, yes. No matter how "easy" a programming language might look, you need to know it, and its pitfalls, because they're there.

There are no silver bullets.

_________________
Every good solution is obvious once you've found it.


Top
 Profile  
 
 Post subject: Re: Why do I despise python
PostPosted: Thu May 18, 2017 9:07 am 
Offline
Member
Member

Joined: Thu Jul 03, 2014 5:18 am
Posts: 72
Location: The Netherlands
I fail to see your point at all... you're complaining about how a language works. Now, if this was a curious feature I might agree, but if I do the same in C:

Code:
void main()
{
     int a, b;
     a = 1;
     b = a;
     a = 100;
}


The value of B will still be 1. It isn't that strange.

_________________
My blog: http://www.rivencove.com/


Top
 Profile  
 
 Post subject: Re: Why do I despise python
PostPosted: Thu May 18, 2017 10:33 am 
Offline
Member
Member
User avatar

Joined: Sun Jul 14, 2013 6:01 pm
Posts: 442
i only see C as a real programing language. i come to this conclusion after trying and/or working in several other languages ( (every random variation of)basic, pascal, php, javascript, c#, c++).

from the languages i know, only C is selfhosting, true crossplatform, separated properly from platform libraries/apis, easy enough for both a newcomer and a senior, proper enough to write literally anything, have a 40 year past behind it while it still survived and popular, proofing its timelessness, have the most serious programs of all time written in it, and its relatively very easy to write a compiler for it. it was also able to avoid the rush of retards who would add playmp3 and createmmorpg function while jerking off, if they could.

second generation of BASIC would also fullfill these demands, but in the last 20 year its evolution taken very bad directions, the most important parts never added to the language, only bullshits, made very bad reputation for the language itself, so i would not put trust into the language any more. (but in theory, it still have the capabilities to do a spectacular comeback - but it will dont make such, the people with serious knowledge left the language very long time ago).

_________________
Operating system for SUBLEQ cpu architecture:
http://gerigeri.uw.hu/DawnOS/index.html


Top
 Profile  
 
 Post subject: Re: Why do I despise python
PostPosted: Thu May 18, 2017 1:22 pm 
Offline
Member
Member
User avatar

Joined: Thu Jul 12, 2012 7:29 am
Posts: 722
Location: Tallinn, Estonia
If I snip all bullshit your post reduces to literally this:

Geri wrote:
.

_________________
Learn to read.


Top
 Profile  
 
 Post subject: Re: Why do I despise python
PostPosted: Thu May 18, 2017 2:23 pm 
Offline
Member
Member
User avatar

Joined: Wed Jan 06, 2010 7:07 pm
Posts: 792
Solar wrote:
Value vs. Reference. Not much of a problem in a language that makes these kind of things explicit, but somewhat of a bummer in languages that want to be "hip" and "better" and hide the differences so they look "cleaner" but really aren't.
Languages like Python or Java that do this "non-primitive values are all by-reference" thing don't do it to be "hip" or "better" or "cleaner," they do it because it massively simplifies and empowers the garbage collector. They're not hiding anything.

_________________
[www.abubalay.com]


Top
 Profile  
 
 Post subject: Re: Why do I despise python
PostPosted: Mon May 22, 2017 3:48 pm 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1489
Location: Athens, GA, USA
If you don't like a given language, that's all good; unless your job is forcing you to use them, then you don't have to.

That having been said, it helps to understand what it is you are saying you don't like, and why they are the way they are.

Solar wrote:
That's why I like sticking to the older languages.


Do I even need to say what I am thinking, here? You, of all people here, should have a better idea of why that are the way they are, and more to the point, how long this approach has been around.

Code:
> (define a 1)
> (define b a)
> a
1
> b
1
> (set! a 100)
> a
100
> b
1


OK, so Scheme isn't the original dialect, but it is only five years newer than C (1973 vs 1968), and the same behavior was true in nearly every Lisp since the original m-expression language definition, before it was even implemented. The basic behavior is mainly due, as Rusky states, to that fact that a symbol (the equivalent of an identifier or variable name) is an name for a reference to the data's address rather than the data's address itself. Since everything is (or can be treated as) going through indirection, assignment becomes setting the reference.

Defining a doesn't set a to 1, it sets a to a pointer to a data cell holding the value of 1; the same pointer is used any time the value 1 is needed. By defining b as a, it is copying the pointer to the value cell, not setting b to a reference to a (to put it another way, it automatically snaps the pointers; there is only one level of indirection in both variables). When a is set (assigned) to 100, it changes the reference a holds, but since b still has its own reference to 1 - not a reference to a - it doesn't change anything about b's value.

This may sound inconsistent, because is looks as if it is treating the primitive values differently; but in fact, it isn't. The operations on numbers and other primitives are always indirected, or behave as if they were - in both (define a 1) and (define b a), it is just copying an address from one symbol to another, but in the first case the 'symbol' is the literal 1. In Lisp, a literal is a symbol, not a syntactic structure, though one which is treated differently in regards to how it gets its own value. Similarly, in Python and Ruby, a literal is just another object, just one whose value is constructed implicitly.

I think that this is what is tripping people up, because they assume that

Code:
a = 1


is assigning the value of 1 to a, while

Code:
b = a


is assigning a pointer to a. Both are, in fact, copying a pointer to an object, but to a C programmer, it looks like the second one is copying a pointer to a variable - something that doesn't quite exist in these languages (but see below).

Mind you, to Lisp, that's just an implementation detail, and most Lisp compilers* (and some Lisp interpreters) will short-circuit references to primitives and smaller data structures. I am not sure if the 'standard' implementations of either Python or Ruby do. I would expect they do, if the developers are anything close to being on the ball about this. Then again, I would have said the same thing about TCO, but Guido stated outright that he disliked it because it smashes the stack (OK, so there are decorators for tail recursion removal, but those are a bit kludgey).

Obviously, Java and C# don't, because they have a separate set of explicitly primitive types that are treated them as local values (data addresses) rather than references, and you cannot have references to them without a wrapper class. IME, this is the worst option of all - it is neither completely explicit, not completely implicit, and the differences in behavior can be confusing even with the explicit typing those languages use. It was originally selected in Java for efficiency reasons, but in retrospect, that makes no sense - efficient algorithms which could convert conceptual references in heap to concrete values on the stack, and which play well with garbage collectors, were already well known (e.g., Chaney's algorithm), and the only thing it did was simplify the compiler (and by only a trivial degree at that).

There are ways to get multiple levels of indirection in these languages, but not with simple assignment - you need to use a list structure, which in Lisp at least, is just pairs of references chained together and with a null in the second value of the last pair. Pairs are shown like this:

Code:
(2 . 3)
(a . b)

where the first is a pair with a reference to the constant 2 and a reference to the constant 3, and the second is a pair of references to the symbols (references) a and b (these are sometimes called 'improper' lists because they fill both cells with non-null references).

A list, then, would actually be a series of pairs which contain one or more references to either another pair, or a null, so:

Code:
; simple list
(a b c d)  => (a . (b . (c . (d . null))))

; nested list, i.e. , a tree
(a b (c d (e f) g))   => (a . (b . ((c . (d . ((e . (f . null)) . (g . null)))) . null))


The same can be done in Python, but Python also has more specialized data types which get used more often (most modern Lisps do too, actually).

--------------
*) Despite its reputation, Lisp is, and always has been, primarily a compiled language; while Slug Russell's big insight involved using the eval and apply functions described in MacCarthy's paper as an interpreter**, that was pretty much an accident, and the original interpreter was used first and foremost for bootstrapping the first compiler. The misconception comes in part from the use of the REPL in development - which behaves like an interpreter, but often is actually a compile-and-go native compiler - and from the ease with which meta-circular interpreters are written in Lisp. The fact that any fool could write a Lisp interpreter - in any language, but especially in Lisp itself - led to a culture that focuses heavily on defining DSLs and extension languages for things which would be done in a more direct and less abstracted manner in most other languages.

**) The eval and apply functions were defined in a publication language which MacCarthy called the 'm-expression' form, but operated on a symbolic list data structure MacCarthy called an 's-expression'. They had the effect of treating an s-expression as a an expression in a modified lambda calculus, with eval calling apply on the first element of the list with the rest of the list as function arguments, and apply taking the list of arguments and calling eval on each one until it got to just a final literal or value, at which point it would call the function being applied with those final return values as it's arguments.

In the paper, they were only intended to demonstrate that the new language was Turing-equivalent (or rather, Church-equivalent, since he based them on the lambda calculus), something that wasn't really clear for a lot of languages at the time. Steve 'Slug' Russell, one of MacCarthy's grad students, was tasked with hand-converting several of the base Lisp functions into assembly code to demonstrate that they were viable as executables, and help plan out the m-expression compiler. However, around Dec 1958, he decided to try implementing the eval and apply functions to see if they could actually work; they did, and it struck him that they could use the s-expressions instead of the m-expressions, and just use eval and apply in a loop - in other words, he realized he had written an interpreter.

_________________
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
μή εἶναι βασιλικήν ἀτραπόν ἐπί γεωμετρίαν
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.


Top
 Profile  
 
 Post subject: Re: Why do I despise python
PostPosted: Tue May 23, 2017 1:32 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7412
Location: Germany
Schol-R-LEA wrote:
Solar wrote:
That's why I like sticking to the older languages.


Do I even need to say what I am thinking, here? You, of all people here, should have a better idea of why that are the way they are, and more to the point, how long this approach has been around.


And the next thing that comes up is a Lisp-alike -- the one type of programming language that I never was able to really wrap my head around. ;-)

I'm not perfect, and I admit it. I'd be scared if I were. ;-)

What I was referring to were those kind of languages that unapologetically expose pointers.

But that's Lisp'ers to you. Always ready to spoil your fun. ;-)

_________________
Every good solution is obvious once you've found it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 35 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group