Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

rust just got 4x more productive [shill thread]

Name: Anonymous 2016-12-16 15:09

Rust designers developed an idiom for concisely propagating errors outwards with a macro called try!:
let file = try!(File::open("file.txt"));
More recently, Rust shipped an even more concise notation for error propagation, the postfix ? operator:
let file = File::open("file.txt")?;

Name: Anonymous 2017-01-19 14:52

>>35
Null references pretty clearly have enough uses to justify their existence. For example, with null references, a linked list node can look like:

typedef struct ll_node {
int val;
struct ll_node *next;
} ll_node;


On a 32-bit platform, that would be eight bytes per node. Without null references, it would become

typedef struct ll_node {
int val;
struct ll_node *next;
bool has_next;
} ll_node;


And since structs are typically aligned based on the alignment of their largest member, that single boolean field would add 4 bytes, or 50%, to the size of each node.

Name: Anonymous 2017-01-19 15:18

>>41
To add on to this, if C didn't have null pointers, programmers would probably resort to putting something like the following in the global scope:

char junk;
void * const null = &junk;


This would allow the programmer to simulate null pointers by following the convention that any pointer pointing to the variable 'junk' be treated as a pointer to invalid data. 'junk' could be used for something to avoid wasting memory, so long as no attempt is ever made to access it through a pointer.

Name: Anonymous 2017-01-19 15:23

>>28
I think you could use references to implement a circularly linked list though. And for regular linked lists, you could have a special "end of list" node, similar to the idea talked about in >>42; you'd create a special linked list node object, and consider any node with a reference to that object to be the end node of a list. Of course that wouldn't be efficient, and there's really no point to it, but it could be done if you really want to.

Name: Anonymous 2017-01-20 5:52

>>18-26,28-43
If null pointers did not exist, it would be necessary to invent them.

Name: Anonymous 2017-01-20 7:30

>>44
Imagine how math was before invention of zero

Name: Anonymous 2017-01-20 8:02

>>45
Also, zero requires special handling/rules(e.g.division by zero,L'Hôpital rules) just like null pointers.

Name: Anonymous 2017-01-20 18:03

>>42
NIL in Lisp was at address zero and both parts were pointers to itself.

>>44-46
If graph theory was around before the invention of zero, there wouldn't have been a null graph.
https://en.wikipedia.org/wiki/Null_graph

in recursively defined data structures K0 is useful for defining the base case for recursion (by treating the null tree as the child of missing edges in any non-null binary tree, every non-null binary tree has exactly two children).
That sounds exactly like the null pointer/null reference.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List