Quantcast
[ 3 / biz / cgl / ck / diy / fa / g / ic / jp / lit / sci / tg / vr / vt ] [ index / top / reports / report a bug ] [ 4plebs / archived.moe / rbt ]

Due to resource constraints, /g/ and /tg/ will no longer be archived or available. Other archivers continue to archive these boards.Become a Patron!

/g/ - Technology


View post   

[ Toggle deleted replies ]
File: 6 KB, 235x205, Screenshot from 2018-05-30 21-53-25.png [View same] [iqdb] [saucenao] [google] [report]
66150063 No.66150063 [Reply] [Original] [archived.moe] [rbt]

Post evidences of retardation of programming language designers.

>> No.66150231

>I don't know how references work

>> No.66150264

>>66150063
I could easily spam this thread with C++, JS and Python proposal papers and documentation.

>> No.66150279
File: 8 KB, 314x151, tm structure.png [View same] [iqdb] [saucenao] [google] [report]
66150279

>>66150063

>> No.66150298
File: 19 KB, 480x640, nigger.jpg [View same] [iqdb] [saucenao] [google] [report]
66150298

>>66150264

>> No.66150318

>>66150279
https://en.wikipedia.org/wiki/Leap_second

>> No.66150323
File: 47 KB, 640x480, sddefault-12-640x480.jpg [View same] [iqdb] [saucenao] [google] [report]
66150323

>>66150231
But thats a closure

>> No.66150341

>>66150279
time is one of the most difficult things for os/language designers, along with languages

>> No.66150383

>>66150279
What triggers me is "day of the month" starts at 1 (so apparently that's acceptable) but then they do "months since January" [0-11] - why not just "month" [1-12] ?

>> No.66150387

>>66150063
wtf, never knew Python was this retarded. Why does it do this?

>> No.66150413

>>66150318
Not this.
>>66150383
THIS.

>> No.66150424

>>66150387
It uses the same list instance each time

Instead you have to do
def f(default=None):
if default is None:
default = []
default.append(10)
print(default)

>> No.66150439

>>66150424
Yea, I was wondering why it doesn't reset each time - the parameter should be initialized again with each call shouldn't it?

>> No.66150461

>>66150298
Well, unless there is more demand, let's start with something meta:
http://open-std.org/JTC1/SC22/WG21/docs/papers/2018/p0977r0.pdf

>> No.66150499

>>66150063
Python is retarded what did you expect ?

>> No.66150503

>>66150063
>>66150424
>>66150439

IMO the real problem is functions like .append() altering the original array instead of just returning a new array with the value appended.
The latter makes for far nicer looking code and should be the standard for all array functions.

>> No.66150526

>>66150264
then do, that's why a thread died for this

>> No.66150549

>>66150341
>https://en.wikipedia.org/wiki/Leap_second
isn't it why the default time format should be Unix epoch time? (with better resolution) it always just increments

>> No.66150586

>>66150439
probably it prepares the array and sets the pointer as the default value under the hood, once resets for new function call it's still the same pointer value thus carries the side effect
wonder if this can lead to memory management error

>> No.66150604

>>66150503
is it supposed to reallocate and copy whole array? are you crazy?

>> No.66150609

>>66150063
>Default parameter values are evaluated from left to right when the function definition is executed. This means that the expression is evaluated once, when the function is defined, and that the same “pre-computed” value is used for each call. This is especially important to understand when a default parameter is a mutable object, such as a list or a dictionary: if the function modifies the object (e.g. by appending an item to a list), the default value is in effect modified. This is generally not what was intended. A way around this is to use None as the default, and explicitly test for it in the body of the function, e.g >>66150424
I've never defined a list/dict inside a parameter, there's really no point to with a dynamic language like Python. instead define it first and then run it through the function, or define it locally inside the function and it behaves like you want it to. had no idea it behaved like this for dicts/lists tho.

>> No.66150688
File: 53 KB, 738x349, pytards.png [View same] [iqdb] [saucenao] [google] [report]
66150688

>>66150526
see >>66150461

But let's go on nice and easy...
Pic related shows two common Python memes:
a) Naming their things differently to hide their fuckups in said things. Compare for "lists" in Python.
b) Resolving stuff at runtime that should be resolved at compile time (and you could even have a check-only mode), even in a dynamically type-checked language. Having mandatory variable declarations could catch typos at compile time. Even VBA, Perl and JS are better at this when in strict mode. From here on, you could think further what else should be resolved at compile time...

>> No.66150747

>>66150503
No, the problem is that the scope of "default" is larger than the function.

>> No.66150765

>>66150688
the joke is solid interpreter could compile given files and statically check for errors nearly as quicklu as python's runtime starts

>> No.66150833

>>66150586
>>66150503
So .append() is effecting the variable at the memory address and the function keeps referring back to that same address. Seems like a pretty simple fuck up from the point of view of the developers of the language, is this meant to be intentional?

>> No.66150848

>>66150765
Maybe even faster.
Remember, all kinds of stuff like doing operator overloading, defining classes and metaclasses are statements.
With compile time types the interpreter would have to parse the source code and construct a type table.
But now it has to parse the source, execute the statements and change the type table, doing more costly memory operations.

>> No.66150854

>>66150604
Of course not.
You append as normal, just copy the pointer.

>> No.66150866
File: 61 KB, 818x264, Screenshot from 2018-05-30 22-55-45.png [View same] [iqdb] [saucenao] [google] [report]
66150866

>>66150833
I looked it up in specs and there is even warning on that

>> No.66150898

>>66150833
Remember when you have to pass "this" to methods?
It's likely another fuckup of spilling interpreter guts excused as "explicit programming".

Man, if there wasn't the Cube guy I'd think the Dutch suck at programming languages.

>> No.66150904

>>66150866
Jesus.

>> No.66150968

>>66150747
>>66150866

Re-using the same default value can lead to huge performance gains, both in speed and memory use, if the default is big.
And the only alternative would be to define the default outside of the scope, which can be quite ugly.

>> No.66151041

>>66150063
Mutability is bad.

>> No.66151167

>>66150063
https://www.youtube.com/watch?v=zt0OQb1DBko

>x: [email protected]
>declare variable x that has a type of unspecified size
this is not a typo

>> No.66151171

>>66150765
>what is technical debt

know to choose different tools for different problems you brainlet

>> No.66151240

>>66150323
>I don't know what closure means

>> No.66151290

>>66150854
>If you make a copy of the pointer you can modify the struct without affecting other copies of the pointer and without allocating a new struct.
Oh, you're retarded

>> No.66151326

>>66150898
You mean functions? Python doesn't have methods, if you use a function as a descriptor it binds the owning instance as the first argument.

>> No.66151371
File: 4 KB, 217x139, Screenshot_2018-05-30_14-36-12.png [View same] [iqdb] [saucenao] [google] [report]
66151371

>>66150063
>appends to the same mutable object
>waa why is this happening
Imagine being too retarded for Python.

>> No.66151435

>>66150866
nice font rendering bro

>> No.66151492

>>66151435
stock Ubuntu on shit low-res display (thinkpad)

>> No.66151499

>>66151371
anon, this is /g/. the ratio of people here who literally have no fucking idea what they're talking about, but will post this kind of shit acting like they're fucking blowing people out of the water, to people who actually have a clue is kinda hilarious. nobody here knows a fucking thing

>> No.66151521

>>66151290
OK, let me write it out for you brainlet:

An array object consists of 3 values:
- a pointer to the first element of the array
- the size of the elements in bytes
- the current length

The "append()" function does two things:
- first it writes a value to (pointer + (length * element_size))
- then it adds 1 to the length

My "append()" function would:
- first it writes a value to (pointer + (length * element_size))
- it would NOT increase the length of the original array, just LEAVE IT THE FUCK ALONE and it would be the same as before
- then return a new array with same pointer, same element size but length+1

>> No.66151626

>>66151521
You can do that already:
>>> old = [1, 2, 3]
>>> new = old + [4]
>>> new
[1, 2, 3, 4]
>>> old
[1, 2, 3]

Append is logically in-place, as it signifies a dynamic array.

>> No.66151705

>>66151521
then you need to distinguish between view and array
>>66151626
he proposes that new and old reference to the same memory
>>> old = [1, 2, 3]
>>> new = old + [4]
>>> new
[1, 2, 3, 4]
>>> old
[1, 2, 3]
>>> old[0] = 666
>>> old
[666, 2, 3]
>>> new
[666, 2, 3, 4]

current behavior makes new copy

>> No.66151830

>>66151521
D already does this
void main()
{
int[] array;
array.reserve = 100;
array ~= 10; //no alloc
auto copy = array;
array ~= 1; //no alloc
copy ~= 5; //extra room already taken, must reallocate
assert(array == [10, 1]);
assert(copy == [10, 5]);
}

>> No.66152036

>>66151326
see >>66150688 a)
They'd be better off not implementing methods at all.
In the end, they'd have dynamic dispatch via dynamic type-checking anyway.

>> No.66152310
File: 53 KB, 630x478, 1525424349229.jpg [View same] [iqdb] [saucenao] [google] [report]
66152310

>>66150063
you just accidentally proved that you yourself don't know what you're doing.

>>> class F():
... def __init__(self):
... self.a, self.b = 0, 1
...
... def __next__(self):
... _ = self.a
... self.a, self.b = self.b, self.a+self.b
... return _
...
... def __iter__(self):
... return self
...
...
>>> f = iter(F())
>>> for _ in range(10):
... print(next(f))
...
...
0
1
1
2
3
5
8
13
21
34


it's called iterators you fucking plebian. learn about the behavior of default values CHRIST.

>> No.66152320

>>66151521
>An array object consists of 3 values:
Python doesn't have arrays.

>> No.66152329

>>66151521
Great idea, but now you broke the GC.

>> No.66152401

>>66152320
see >>66150688

>> No.66152681

>>66150279
C is deprecated like Pascal

>> No.66152697

>>66150063
functional languages are memes, i dont even know why you think this deserves thread

>> No.66153474

>>66150383
>>66150413
In the history there is a time where they lost 11 days when changing the calendar.
There can be a month where the first of X doesn't exist, where days since the first of month is undefined; or that the next day of 15/X(14/X-1) is 27/X, but from the definition of days since month, it would be (15/X-1), not (26/X-1).

>> No.66153683

Java streams

>> No.66154260

>>66150424
And if you want type hints
from typing import List

def f(default: List[int] = None): # Can put any type in the brackets
if default is none:
default = []
...

>> No.66155839
File: 28 KB, 936x772, 1512287655455.png [View same] [iqdb] [saucenao] [google] [report]
66155839

>>66150063
>>66150387
>>66150499
>set default parameter as an instance of an object
>call method to mutate said object
WAHHH WY IT DO DIS PYTON RETARD

>> No.66156163

>>66150063
op demonstrates why reference types without referential transparency are fucking cancerous

value semantics > all

>> No.66156225

>>66155839
The default parameter should be an expression, not a pre-evaluated value. There are basically no circumstances where the current semantics are desired; the language implementor should have realized this and implemented default params as expressions accordingly. Besides, you can still get the previous behavior by lifting the default object to a global variable and referencing it in the default param; this way the behavior is very explicit.

>>66156163
Yeah, I've been avoiding languages like Python/Java that tend have rampant use of mutable references lately. I'm happy about that.

>> No.66156236

Fun Python fuckery:

g = "ok"

def func1():
print(g) # -> "ok"

def func2():
print(g) # runtime error
g = "notok"

>> No.66156245

>>66156236
what the fuck? is this some variable hoisting bullshit

>> No.66156255

>>66151521
How would that work if you use your new append twice on the original array?

a = [1,2] # len=2, ptr=0x1234, in memory: [1] [2] [garbage ...]
b = a.append(3) # in memory: len=3, ptr=0x1234, [1] [2] [3] [garbage ...]
c = a.append(4) # in memory: len=3, ptr=0x1234, [1] [2] [4] [garbage ...]

print(b[2]) # -> 4 ... wtf??

>> No.66156258

>>66156225
I could see this behaviour being potentially useful for tail recursion.

>> No.66156265

>>66156258
? This doesn't have anything to do with tail recursion, and Python *explicitly* doesn't support tail recursion anyways ....

>> No.66156276

>>66150063
[] == false //true
![] == false //true
!![] == false //false

>> No.66156280

>>66156276
C'mon, JavaScript's == is a dead horse by now.

>> No.66156323

>>66150609
Thanks man
This is a great explanation
Unironically, this is why I sometimes love /g/

>> No.66156364

>>66150688
>Having mandatory variable declarations could catch typos at compile time
Why though?
Python is a dynamic language where everything is an object
In my opinion the most elegant language of the imperative dynamic scripting languages
Why mess up the syntax and semantics by implementing something that wasn't intended
Just use another language

>> No.66156378

>>66151371
Nice

>> No.66156412

>>66151499
On the other hand that's what good about /g/
By letting people anonymously defend ludicrous ideas you can either tear them down completely (thus learning why the best practice is really the best) or proving that the ludicrous idea wasn't so ludicrous after all and can be useful
Either way you learn something that you wouldn't learn in an echo chamber
That's why I like /g/ and I think it's both fun and educational

>> No.66157463

>>66156364
PEP 484
PEP 526

Python supports type annotations since version 3.5. It's not mandatory, but you can use it if you want.

>> No.66157478

>>66156364
wrong person
meant for >>66150688

>> No.66157550

>>66150063
The way shit is passed in python is so fucking stupid

>> No.66157608

>>66150063
Based JavaScript doesn't do this

>> No.66157927

>>66156364
This has nothing to do with objects.
This has also nothing to do with implementing something that wasn't intended.
This is solely GVR not knowing the first thing about language design.
There is nothing elegant about dynamics that give literally no benefits but defer error checking to runtime.

>hurr durr just use another language
That's not how language economics works. As soon as enough cancermonkeys fall for it, one will be forced to face it sooner or later. The only way to be safe is to destroy Python once and for all.

>> No.66157946

>>66157463
That has little to do with what >>66150688 is complaining about. Also, optional tacked on type anotations are close to useless.

>> No.66158167

>>66150063
As much as I love Erlang..

https://stackoverflow.com/questions/4776033/how-to-change-an-element-in-a-list-in-erlang

>> No.66158683

>>66150503
I didn't know it was even possible, but sure. Make python even slower. Maybe people will finally stop using it.

>> No.66160628
File: 58 KB, 576x402, 1483208260516.png [View same] [iqdb] [saucenao] [google] [report]
66160628

>> No.66160830

>>66150549
Unix time is not perfect.
It always increments, but slows down during leap seconds.
The best would be TAI or Temps Atomique International. It's completely based on atomic time and not on earth rotation, so it's continuous and does not include leap seconds.

The smartest programmer in the world figured that out: https://cr.yp.to/libtai.html

>> No.66160848

>>66156245
g is redefined in the scope of func2, so python doesn't go looking in globals

On a technical level, each function maintains a dictionary of variables used in the function, and the interpreter will only call back to the global dictionary if the requested key is not in the local dictionary

>> No.66160963

>>66158167
lists are linked lists in erlang
or are you hoping there would be a built-in function?

>>
Name (leave empty)
Comment (leave empty)
Name
E-mail
Subject
Comment
Password [?]Password used for file deletion.
Captcha
Action