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

Cad

<Bronze Donator>
24,492
45,417
Fun recursive vs iterative CS question:

I'm building a hex tree where each node has the address of its six neighbors if they exist ex:
I start out with one node and as I need to expand the space it occupies I keep adding nodes (and have to assign the new nodes to its neighbors if they exist!!). Once I'm done I need to deallocate the memory space of all those nodes without leaving behind any nodes or double deleting.

I'm going to write the recursive implementation for delete and would be interested to see the iterative implementation.

Note that I might give up and try a completely different and better approach once I realize how slow searching is and how much better octrees or kdtrees are for my problem.

Software engineering bonus question: Find a current implementation that does all this with better performance and reliability than I can.
Why can't you do something like:

 

Tuco

I got Tuco'd!
<Gold Donor>
45,453
73,543
I think that implementation would multi delete. When you add the neighbor to the list you'll have to remove that neighbor's reference to tempNode.
 

Cad

<Bronze Donator>
24,492
45,417
I think that implementation would multi delete. When you add the neighbor to the list you'll have to remove that neighbor's reference to tempNode.
Where is the neighbors reference to tempNode ever created? TempNode is a local variable/pointer (depending on language of implementation) used to point at the node we're deleting.
 

Tuco

I got Tuco'd!
<Gold Donor>
45,453
73,543
Right, but after you delete that node, won't its neighbors have a reference to it? needing something like
 

Cad

<Bronze Donator>
24,492
45,417
Right, but after you delete that node, won't its neighbors have a reference to it?
You're going to systematically delete all the neighbors too. So you'll get those references when you hit them.
 

Asshat wormie

2023 Asshat Award Winner
<Gold Donor>
16,820
30,964
Your guys use of (... != null) is making me twitch. Please for the love of god (!tempnode.neighbor).
 

Tenks

Bronze Knight of the Realm
14,163
606
I find the latter far less readable and it compiles down to the same stuff anyways
 

Tuco

I got Tuco'd!
<Gold Donor>
45,453
73,543
I usually use (!tempNode.neighbor) because lazy but use (tempNode.neighbor != null) when describing things to people because it's more explicit and I don't know how pointers work in all language.

Both are about the same to me in terms of readability and probably compile the same.
 

Asshat wormie

2023 Asshat Award Winner
<Gold Donor>
16,820
30,964
But the standards
frown.png
 

Tenks

Bronze Knight of the Realm
14,163
606
My issue is when someone is quickly reading over my code or I quickly read over someone's code parenthesis followed by not operator often blends together. It is too simple to overlook so I'm always very explicit with my null checks anymore.
 

Tuco

I got Tuco'd!
<Gold Donor>
45,453
73,543
But the standards
frown.png
If I made a standard I'd probably make it favoring Tenks. When people get uppity about whether address checks should be !address or address != null it poisons the idea of coding standards.
 

Asshat wormie

2023 Asshat Award Winner
<Gold Donor>
16,820
30,964
If I made a standard I'd probably make it favoring Tenks. When people get uppity about whether address checks should be !address or address != null it poisons the idea of coding standards.
I am mostly being facetious. I just really like code to be as clean as can be.
 

Cad

<Bronze Donator>
24,492
45,417
I am mostly being facetious. I just really like code to be as clean as can be.
I like it to be really obvious what something is doing so shorthand notations that even slightly obfuscate something for the next monkey that is going to read my code and fuck it up bother me.

Also I quit programming in like 2006 so ... ymmv hah.
 

Citz

Silver Squire
180
8
I'm used to see != null with C# since you can only use the ! operator on a boolean.
 

Asshat wormie

2023 Asshat Award Winner
<Gold Donor>
16,820
30,964
Tuco was playing with pointers. The value of a null pointer is equivalent to 0 which is equivalent to false. Thats why !pointer works.
 

Lendarios

Trump's Staff
<Gold Donor>
19,360
-17,424
Which is very language specific. The better code will be a comparison with null, to avoid any misunderstanding. There are languages that allows you do to
int c =4;
if (c == false) then ...
Which compiles and works(by exploding the implementation of bool and int ), but it is not the right way on modern languages.
 

Asshat wormie

2023 Asshat Award Winner
<Gold Donor>
16,820
30,964
Which is very language specific. The better code will be a comparison with null, to avoid any misunderstanding. There are languages that allows you do to
int c =4;
if (c == false) then ...
Which compiles and works(by exploding the implementation of bool and int ), but it is not the right way on modern languages.
My comment was strictly limited to the realm of c/c++ since that is what tuco programs in according to him. As far as I know, and I really don't, !pointer is idiomatic in c.
 

Tuco

I got Tuco'd!
<Gold Donor>
45,453
73,543
My comment was strictly limited to the realm of c/c++ since that is what tuco programs in according to him. As far as I know, and I really don't, !pointer is idiomatic in c.
There's two points here:
1. Only a minority of people reading this thread probably have heavy experience in C, so != null is more clear to people.
2. Even within veterans of C, different programmers use different ways of pointer-checking and to be adament that one way is right is silly.
 

Asshat wormie

2023 Asshat Award Winner
<Gold Donor>
16,820
30,964
There's two points here:
1. Only a minority of people reading this thread probably have heavy experience in C, so != null is more clear to people.
2. Even within veterans of C, different programmers use different ways of pointer-checking and to be adament that one way is right is silly.
I am not adamant about it. Just having a conversation. There is zero difference between the two.
 

Obtenor_sl

shitlord
483
0
And here I am as a Ruby Developer thinking "jeez, what a mess, in Ruby you only have to ask: variable.nil?"

That's why I guess I love the Ruby language, it's so like 'natural' language it scares me. 1..5 do { xyz }, or array.each ... or variable.nil?. So easier and natural to perform operations and checks.