IT/Software career thread: Invert binary trees for dollars.

  • Guest, it's time once again for the hotly contested and exciting FoH Asshat Tournament!



    Go here and fill out your bracket!
    Who's been the biggest Asshat in the last year? Once again, only you can decide!

Control

Ahn'Qiraj Raider
2,096
5,211
I'm talking about VP-level people though.
You'd think that curve would change the higher in an organization you go, but at that level, the curve is really measuring political skill/positioning. And that's probably negatively correlated to the "actually being useful" curve...
 
  • 1Like
Reactions: 1 user

Mist

Eeyore Enthusiast
<Gold Donor>
30,272
22,006
I think my original post was misinterpreted. I was not saying there was a high rate of unqualified people who'd taken that career path upwards, just that the subset who were dumb were really dumb.
 

Mist

Eeyore Enthusiast
<Gold Donor>
30,272
22,006
PS: I have a 3am migration/cutover project tonight and I'm not happy, though I will say that old-school MMO players are much better equipped for 3am projects than basically anyone else. :)
 
  • 2Like
Reactions: 1 users

Deathwing

<Bronze Donator>
16,315
7,313
Found this in a coding test I was grading.

Python:
with open('test.txt', 'r') as file:
    file = file.read()
 
  • 1Worf
Reactions: 1 user

Deathwing

<Bronze Donator>
16,315
7,313
I've been musing on this. I put that code in the python interpreter and it doesn't get mad. Meaning the the syntactic sugar that `with` represents(try/finally) did not run the finally block, or not called on explicitly `file`. Did `with` remember what `file` originally represented and close the file handle for you? Or do you have a dangling file handle?





I still failed the test. Don't write code that moronic even if the Python interpreter is smart enough to compensate.
 
  • 1Like
Reactions: 1 user

Neranja

<Bronze Donator>
2,605
4,143
Or do you have a dangling file handle?
When the "with" block starts, "file" is the actual filehandle you opened and can operate on. Then in that one line in the with block, the variable "file" gets reassigned to the read contents of the file, but only after the file.read() executed. Its like "x = x + 1", x only gets assigned the new value after the right hand side calculation is done. The actual "file" handle is freed after that, because its reference counter drops to zero, as the variable "file" is no longer referencing it.

It's still shit code, though:
a) Name variables by their purpose, not by their type. Don't go around naming variables "string1, string2, int1, int2"
b) It shadows the built-in name "file"
 

Asshat wormie

2023 Asshat Award Winner
<Gold Donor>
16,820
30,963
Just shows a lack of understanding of what the objects are that one is manipulating. The assignment took a file object, or TextIOWrapper to be precise, and turned that poop into a string, destroying all of the functionality gained by creating a file object in the first place. Clearly someone just memorized some code but has no idea what it actually does.
 

Deathwing

<Bronze Donator>
16,315
7,313
When the "with" block starts, "file" is the actual filehandle you opened and can operate on. Then in that one line in the with block, the variable "file" gets reassigned to the read contents of the file, but only after the file.read() executed. Its like "x = x + 1", x only gets assigned the new value after the right hand side calculation is done. The actual "file" handle is freed after that, because its reference counter drops to zero, as the variable "file" is no longer referencing it.

It's still shit code, though:
a) Name variables by their purpose, not by their type. Don't go around naming variables "string1, string2, int1, int2"
b) It shadows the built-in name "file"
Will the garbage collector be that aggressive? And what happened to the with block wanting to call the file handle's __exit__ function?

Friend and I had the same discussion about shadowing. In Python3, turns out file is no longer a builtin!



I tried the piece of code again while attaching strace to the interpreter. The file handle is indeed closed after exiting the with, but I can't tell why specifically.
 

Phazael

Confirmed Beta Shitlord, Fat Bastard
<Aristocrat╭ರ_•́>
14,020
29,913
I'm talking about VP-level people though.
VP level people are nearly always retards, in my experience. I have never worked a gig where the team leads did not know more than the CTO as well.
 

Neranja

<Bronze Donator>
2,605
4,143
Will the garbage collector be that aggressive? And what happened to the with block wanting to call the file handle's __exit__ function?
For practical purposes, the garbage collector cleans up at the __exit__() method, when the "local" variables are to be removed. Technically, the "with" statetment is a "try ... except ... finally" around a context manager, which works like an object. The assignments in the "with" statement itself are considered local to that context and attached to the context manager, so they get cleaned up when the context manager is removed itself. The context manager basically has a reference to the first variable "file", but the new variable called "file" is created as a different variable as it gets reassigned.

I tried the piece of code again while attaching strace to the interpreter. The file handle is indeed closed after exiting the with, but I can't tell why specifically.
You can't really debug this with the Python interpreter. The "with" statement is a compound statement, and those only get executed once the compound statement has been fully parsed. If you have a Linux system it would look a bit like this

Python:
#!/bin/env python3
import os
import sys
import subprocess

with open('test.txt', 'r') as file:
  print(type(file))
  print(sys.getrefcount(file))
  os.system('ls -al /proc/%d/fd' % os.getpid())
  file = file.read()
  print(type(file))
  print(sys.getrefcount(file))
  os.system('ls -al /proc/%d/fd' % os.getpid())

os.system('ls -al /proc/%d/fd' % os.getpid())

This would output something like this:

Code:
<class '_io.TextIOWrapper'>
3
total 0
dr-x------ 2 user user  0 Jun 23 15:45 .
dr-xr-xr-x 9 user user  0 Jun 23 15:45 ..
lrwx------ 1 user user 64 Jun 23 15:45 0 -> /dev/pts/13
lrwx------ 1 user user 64 Jun 23 15:45 1 -> /dev/pts/13
lrwx------ 1 user user 64 Jun 23 15:45 2 -> /dev/pts/13
lr-x------ 1 user user 64 Jun 23 15:45 3 -> /home/user/test.txt
2
<class 'str'>
total 0
dr-x------ 2 user user  0 Jun 23 15:45 .
dr-xr-xr-x 9 user user  0 Jun 23 15:45 ..
lrwx------ 1 user user 64 Jun 23 15:45 0 -> /dev/pts/13
lrwx------ 1 user user 64 Jun 23 15:45 1 -> /dev/pts/13
lrwx------ 1 user user 64 Jun 23 15:45 2 -> /dev/pts/13
lr-x------ 1 user user 64 Jun 23 15:45 3 -> /home/user/test.txt
total 0
dr-x------ 2 user user  0 Jun 23 15:45 .
dr-xr-xr-x 9 user user  0 Jun 23 15:45 ..
lrwx------ 1 user user 64 Jun 23 15:45 0 -> /dev/pts/13
lrwx------ 1 user user 64 Jun 23 15:45 1 -> /dev/pts/13
rrwx------ 1 user user 64 Jun 23 15:45 2 -> /dev/pts/13

Friend and I had the same discussion about shadowing. In Python3, turns out file is no longer a builtin!
Python is not even my main job, but I still have to work with so much old Python 2 code, that my brain basically mixed and blended everything together in one big "Python" pile.
 
  • 1Like
Reactions: 1 user

Deathwing

<Bronze Donator>
16,315
7,313
For practical purposes, the garbage collector cleans up at the __exit__() method, when the "local" variables are to be removed. Technically, the "with" statetment is a "try ... except ... finally" around a context manager, which works like an object. The assignments in the "with" statement itself are considered local to that context and attached to the context manager, so they get cleaned up when the context manager is removed itself. The context manager basically has a reference to the first variable "file", but the new variable called "file" is created as a different variable as it gets reassigned.


You can't really debug this with the Python interpreter. The "with" statement is a compound statement, and those only get executed once the compound statement has been fully parsed. If you have a Linux system it would look a bit like this

Python:
#!/bin/env python3
import os
import sys
import subprocess

with open('test.txt', 'r') as file:
  print(type(file))
  print(sys.getrefcount(file))
  os.system('ls -al /proc/%d/fd' % os.getpid())
  file = file.read()
  print(type(file))
  print(sys.getrefcount(file))
  os.system('ls -al /proc/%d/fd' % os.getpid())

os.system('ls -al /proc/%d/fd' % os.getpid())

This would output something like this:

Code:
<class '_io.TextIOWrapper'>
3
total 0
dr-x------ 2 user user  0 Jun 23 15:45 .
dr-xr-xr-x 9 user user  0 Jun 23 15:45 ..
lrwx------ 1 user user 64 Jun 23 15:45 0 -> /dev/pts/13
lrwx------ 1 user user 64 Jun 23 15:45 1 -> /dev/pts/13
lrwx------ 1 user user 64 Jun 23 15:45 2 -> /dev/pts/13
lr-x------ 1 user user 64 Jun 23 15:45 3 -> /home/user/test.txt
2
<class 'str'>
total 0
dr-x------ 2 user user  0 Jun 23 15:45 .
dr-xr-xr-x 9 user user  0 Jun 23 15:45 ..
lrwx------ 1 user user 64 Jun 23 15:45 0 -> /dev/pts/13
lrwx------ 1 user user 64 Jun 23 15:45 1 -> /dev/pts/13
lrwx------ 1 user user 64 Jun 23 15:45 2 -> /dev/pts/13
lr-x------ 1 user user 64 Jun 23 15:45 3 -> /home/user/test.txt
total 0
dr-x------ 2 user user  0 Jun 23 15:45 .
dr-xr-xr-x 9 user user  0 Jun 23 15:45 ..
lrwx------ 1 user user 64 Jun 23 15:45 0 -> /dev/pts/13
lrwx------ 1 user user 64 Jun 23 15:45 1 -> /dev/pts/13
rrwx------ 1 user user 64 Jun 23 15:45 2 -> /dev/pts/13


Python is not even my main job, but I still have to work with so much old Python 2 code, that my brain basically mixed and blended everything together in one big "Python" pile.
Been working with Python as my main language(but not my main job, QA engineer/manager) for 5+ years, but learned a few things from your post, thanks!

What's the 3rd reference to `file` initially? Local, context manager, and...? I looked at the documentation for `with` and the semantic equivalent isn't helping much in this regard.
 

Bandwagon

Kolohe
<Silver Donator>
22,495
58,986
I don't know enough to even know how to ask this question correctly, but here goes -

I use Postman to construct and test the query parameters in REST API post or get calls. Some of them just take a URL to the api, then a bunch of parameters. Others, I have to enter a bunch of non-readable shit into the "body".

What is the difference between these? Is there a name for the distinction, or a name for one vs the others? I'm trying to understand the differences and importance between the two, but don't even know what to search for.

(Please tag me if you reply....this thread isn't in my usual rotation)
 

Neranja

<Bronze Donator>
2,605
4,143
Some of them just take a URL to the api, then a bunch of parameters. Others, I have to enter a bunch of non-readable shit into the "body".
I think what you want to know is the difference in HTTP methods for REST:

GET is used when only retrieving data, and it is implied that it does not change any data (like retrieving records), so what data to retrieve can be encoded only in the URL.
POST is used when you are commiting data, and data is sent in the body of the HTTP transfer. This usually makes the browser warn you, that if you navigate back that you would "re-post" data already sent.

There are others (read the link above), but that's basically the difference of the two you mentioned.
 

Bandwagon

Kolohe
<Silver Donator>
22,495
58,986
I think what you want to know is the difference in HTTP methods for REST:

GET is used when only retrieving data, and it is implied that it does not change any data (like retrieving records), so what data to retrieve can be encoded only in the URL.
POST is used when you are commiting data, and data is sent in the body of the HTTP transfer. This usually makes the browser warn you, that if you navigate back that you would "re-post" data already sent.

There are others (read the link above), but that's basically the difference of the two you mentioned.
I don't think that the distinction is just GET vs POST since I have both in my scenarios that are only using the URL and ?query= parameters, but thanks for the summary on the distinction between those two. I'll go take a look at the full link now and see if I can make more sense of it. Thanks!
 

Ao-

¯\_(ツ)_/¯
<WoW Guild Officer>
7,879
507
I don't think that the distinction is just GET vs POST since I have both in my scenarios that are only using the URL and ?query= parameters, but thanks for the summary on the distinction between those two. I'll go take a look at the full link now and see if I can make more sense of it. Thanks!
It's post vs something else... my brain is fuzzy. One is parameters passed via URL the other is in the body of the reply? I think? I hate the internet.
 

Deathwing

<Bronze Donator>
16,315
7,313
Any url action can use the query variables(the stuff after the ?). POST actions do indeed put their form data in the response body.
 
  • 1Like
Reactions: 1 user

Bandwagon

Kolohe
<Silver Donator>
22,495
58,986
Maybe I'm just confused because Integromat does that automatically for me (when I thought it wasn't), but I have to do it manually when I'm making calls in Postman.
1624653323244.png