Programming thread

  • 🧊 New server is in an office waiting on a mexican.
  • Want to keep track of this thread?
    Accounts can bookmark posts, watch threads for updates, and jump back to where you stopped reading.
    Create account
Also teaches horrible habits because of a lack of language support. Like using exceptions for regular control flow, down to loops being ended by raising an exception
I don't know, I feel something like that could work well, with a coherent idea behind it. Of course, now that it's mentioned, I'm not aware of a single other language that does it that way.
 
The more I learn about programming and Python, the worse the latter looks in every respect, so may I have a link to read more about why it's secretly a good thing the dipshit who made this language refuses to mentor white men?
Well, that's not very Pythonic of you.
Also teaches horrible habits because of a lack of language support. Like using exceptions for regular control flow, down to loops being ended by raising an exception
I think the only thing I like about Python comes from a lack of language support for private/protected interfaces. I should be allowed to extend and override an inherited class any way I want. The author of a module can't read minds or divine the future, it's not his job to tell my code how it can or can't inherit his classes.
 
Well, that's not very Pythonic of you.

I think the only thing I like about Python comes from a lack of language support for private/protected interfaces. I should be allowed to extend and override an inherited class any way I want. The author of a module can't read minds or divine the future, it's not his job to tell my code how it can or can't inherit his classes.
afaict classes in python are basically just functions with other functions accessible via . notation anyways

deep inspection being possible is nice though
 
Actually, functions are just objects with a __call__() method. Dunders are cursed knowledge.
twitchy.gif

Speaking of cursed knowledge: You can change default values of functions at runtime.

oh and if you have operations on the default parameters that mutate it, congrats, it now mutates it for every other call of that function (most commonly, using the empty list as a default parameter)
 
Last edited:
View attachment 9902777
Speaking of cursed knowledge: You can change default values of functions at runtime.
in python 2 you could change the values of small integer literals (range from -5 to 256), they're cached in memory as PyIntObjects for some reason
Python:
import ctypes

# some fucking magic offset i dunno
offset = ctypes.sizeof(ctypes.c_size_t) + ctypes.sizeof(ctypes.c_voidp)

int_entry = ctypes.c_long.from_address(id(69) + offset)
int_entry.value = 420

print 69     # 420
print 35 + 34  # 420
 
Last edited:
in python 2 you could change the values of small integer literals (range from -5 to 256), they cached in memory as PyIntObjects for some reason
Python:
import ctypes

# some fucking magic offset i dunno
offset = ctypes.sizeof(ctypes.c_size_t) + ctypes.sizeof(ctypes.c_voidp)

int_entry = ctypes.c_long.from_address(id(69) + offset)
int_entry.value = 420

print 69     # 420
print 35 + 34  # 420
I recall that Java lets you do something similar with its internal cache of small-valued boxed Integer objects.
 
Lisps usually have optimizations for small integers, called FIXNUMs, without fucking it up like Python managed. It's pretty simple: Small integers have a different representation that avoids the overhead of BIGNUMs, largely without making this visible other than to code which wants to know the boundary.
 
in python 2 you could change the values of small integer literals (range from -5 to 256), they're cached in memory as PyIntObjects for some reason
Python:
import ctypes

# some fucking magic offset i dunno
offset = ctypes.sizeof(ctypes.c_size_t) + ctypes.sizeof(ctypes.c_voidp)

int_entry = ctypes.c_long.from_address(id(69) + offset)
int_entry.value = 420

print 69     # 420
print 35 + 34  # 420
Of all the languages that allow you to do something like this, this is by far the dumbest. Fortran uses call by value-return, where parameters are moved into a subroutine's argument variables (the addresses of which are known at compile-time, because classic Fortran didn't allow recursion, so all variables were like C's static locals) and then copied back out upon return, and the IBM 704 and its successors didn't allow for immediate operands, which meant that all constants in an expression had to be loaded in from a constant table, so FORTRAN I would let you pass in an entry from the constant table as an argument and would then mutate the constant table by copying the result value back out. (They fixed this in FORTRAN II, where non-variable arguments got copied in, but didn't get copied back out upon return. And if you're wondering why they didn't just put the constant table in the RODATA segment, it's because the hardware had no memory protection, so you couldn't have read-only data.)
Code:
       CALL roody-poo(69)
       WRITE (6, 10) 69
10     FORMAT (I5 /)
       STOP
       END

       SUBROUTINE roody-poo(N)
       N = 420
       RETURN
       END

In Forth, a procedure (which the language calls a "word") name can be any sequence of non-whitespace characters. Historically, it was implemented using threaded code and the code generated to push an integer literal onto the parameter stack would be a pointer to the word that does the pushing (usually called LIT or (LIT)), followed by the literal itself, and implementations would define words whose identifiers were numeric literals and whose only action was to push that value onto the stack, since each reference to the literal would then be half the size (just a pointer to the word). While this usually consisted of
Code:
-1 CONSTANT -1   0 CONSTANT 0   1 CONSTANT 1   2 CONSTANT 2
You could also define abominations like
Code:
420 CONSTANT 69
69 . CR  ( call word "69" and print its return value of 420 )
069 . CR  ( push literal 69 and print it )

You can at least understand why these languages allowed you to change the value of an integer literal, since one was the very first compiler ever and the implementors didn't know then what we know now, and the other is just an extremely generalized notion of "identifier" that trusts the programmer to be a mature adult who won't do anything stupid (and it lets you use the standard ASCII penis 8==D as an identifier, so it's perfect just as it is). In Python's case, on the other hand, it's just a really bad implementation that lets you mutate a constant table because they were too lazy to implement an immutable structure and substituted a mutable structure because they already had one present in their standard library.
 
Back
Top Bottom