Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Fergus Mac Roich
Nov 5, 2008

Soiled Meat

sarehu posted:

If you want to make a language without primitive arrays, be my guest. It's just a bad idea.

Non-rhetorical question for you: what do you mean?

You may very well know something I don't, I just don't understand what primitive arrays have to do with nullable references.

Fergus Mac Roich fucked around with this message at 06:23 on Dec 28, 2016

Adbot
ADBOT LOVES YOU

Deep Dish Fuckfest
Sep 6, 2006

Advanced
Computer Touching


Toilet Rascal

Brain Candy posted:

arrays are good if no one knows you are using them

corollary: they're almost always good in c because most of the time even the compiler doesn't know you're using them!

JewKiller 3000
Nov 28, 2006

by Lowtax

Fergus Mac Roich posted:

Non-rhetorical question for you: what do you mean?

i suspect that by "array" he means the C interpretation, i.e. "data structure whose members can be accessed in constant time, because they exist in a contiguous memory space, at a constant offset from each other". many textbook algorithms require this data structure to achieve their ideal performance

Fergus Mac Roich posted:

You may very well know something I don't, I just don't understand what primitive arrays have to do with nullable references.

ok, now i want to allocate one of these arrays as described above. i'd like an array of (pointers to) Car objects, which can hold 10 elements. how do i initialize my array before i assign any members?

the answer is that i use an option type and initialize the array members to None, but that doesn't occur to c programmers

JewKiller 3000 fucked around with this message at 06:29 on Dec 28, 2016

Fergus Mac Roich
Nov 5, 2008

Soiled Meat

JewKiller 3000 posted:

i suspect that by "array" he means the C interpretation, i.e. "data structure whose members can be accessed in constant time, because they exist in a contiguous memory space, at a constant offset from each other". many textbook algorithms require this data structure to achieve their ideal performance

He'd be obviously correct if that were all there were to it, but the context of his comment is whether people are justified in complaining about nullable references.

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde
nobody mention cache misses or page faults :ninja:

Athas
Aug 6, 2007

fuck that joker

JewKiller 3000 posted:

ok, now i want to allocate one of these arrays as described above. i'd like an array of (pointers to) Car objects, which can hold 10 elements. how do i initialize my array before i assign any members?

the answer is that i use an option type and initialize the array members to None, but that doesn't occur to c programmers

No, that is a terrible solution, you would not be able to create an array of non-option values. One good solution is to construct arrays using a "replicate" function/construct that is given a size and a default element, and creates an array with that many copies of the default element. Another solution is a generator function, where you give a size and a function, and the function is called with an index to construct each element.

Creating a blank or uninitialized array is basically memory allocation. Which is fine if your language is One Of Those Languages, but should probably not be available in more high level settings.

gonadic io
Feb 16, 2011

>>=

Athas posted:

No, that is a terrible solution, you would not be able to create an array of non-option values. One good solution is to construct arrays using a "replicate" function/construct that is given a size and a default element, and creates an array with that many copies of the default element. Another solution is a generator function, where you give a size and a function, and the function is called with an index to construct each element.

Creating a blank or uninitialized array is basically memory allocation. Which is fine if your language is One Of Those Languages, but should probably not be available in more high level settings.

note that in rust it's perfectly fine (in unsafe code) for your default value to be mem::uninitialized (which is not that different from a null pointer in this context*). then you can provide the generator as a for-loop on top of the default value constructor

*: by which I mean that it's an extra "poisoned" value that will gently caress you up if you try to read it. the difference is that you can't test for uninitialized memory.

gonadic io fucked around with this message at 10:35 on Dec 28, 2016

qntm
Jun 17, 2009

JewKiller 3000 posted:

ok, now i want to allocate one of these arrays as described above. i'd like an array of (pointers to) Car objects, which can hold 10 elements. how do i initialize my array before i assign any members?

the answer is that i use an option type and initialize the array members to None, but that doesn't occur to c programmers

a pointer to Car counts as a "primitive" now?

gonadic io
Feb 16, 2011

>>=

qntm posted:

a pointer to Car counts as a "primitive" now?

if you use the constructor you get a vehicle pointer and can cast it to car if you want

sarehu
Apr 20, 2007

(call/cc call/cc)

Fergus Mac Roich posted:

Non-rhetorical question for you: what do you mean?

You may very well know something I don't, I just don't understand what primitive arrays have to do with nullable references.

So basically people have answered this, but your language has to be built on icky high level concepts or have a lot of, let's say, complications if you want to force everything to be initialized, or to have its initialization state known statically. And a big one is that you can't just like, make an array, and set it to be uninitialized or partly initialized. You can't implement ArrayList yourself, you can't build other advanced data structures, without going, say, "beneath" the language. Or having types to build that stuff upon. Like something like this:

code:
class BoundedBuf<T> {
  // 0 <= lowerBound <= upperBound <= size.
  int size();
  int lowerBound();
  int upperBound();
  int pushFront(T x);  // sets lowerBound = lowerBound - 1, or throws
  int pushBack(T x);  // sets upperBound = upperBound + 1, or throws
  // throws if index out of range, i.e. index < lowerBound or index >= upperBound
  T get(int index);
  void set(int index, T value);  // throws if index out of range
}
You could build ArrayList on top of that, certain pieces of other data structures. But not a circular queue (needs two initialized regions) or other stuff with a bunch of "holes." What is the overall benefit? Does option really help? I've seen Servo crash on an .unwrap() more than I've seen null pointer dereferences in some C++ software I work on.

sarehu
Apr 20, 2007

(call/cc call/cc)
It's like parking your car. As you well know (I hope), if you park your car in a shopping center or apartment complex that you frequent, there's the question: where should you park it? The answer is, in the same place 99.9% of the time! That way, you never forget where you park it. And if, one day, for some reason, you park it in a different location, that's weird enough that you won't forget where you parked it.

:iiaca: <- edit: fail

The same thing is how you should use null pointers. Don't use them, design your code around needing them! If the language helps out with that, hooray, but it's not that important. But then in the 0.1% case where a pointer can be null, it's weird enough that you won't forget. It's like, okay, this is null, and that's a big deal!

And if you want to drop a dangling reference that'll never get used again, you don't have to refactor your code to use option.

Ideally programming languages wouldn't let you compare objects for reference equality with null. Any usage of a null pointer should reliably throw an exception. (In such a language, people wouldn't be able to get away with designing "handy" treatment of null pointers in their API's.)

sarehu fucked around with this message at 15:14 on Dec 28, 2016

tef
May 30, 2004

-> some l-system crap ->
who keeps yelling OPTION TYPES at my house. show yourself coward i will never use option types

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
my friend, have you considered that option types are an example of a monad

30 TO 50 FERAL HOG
Mar 2, 2005



* a heckler in the audience *

c# events are convoluted and bad!

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

BiohazrD posted:

* a correct opinion-haver in the audience who's about to get shaggared *

c# events are convoluted and bad!

raminasi
Jan 25, 2005

a last drink with no ice
they're good but could be better

Slurps Mad Rips
Jan 25, 2009

Bwaltow!

a man falls through the earth and into parisian catacombs. taking a torch from the wall he spies row upon row of skeletons. grasping the nearest by the shoulders, he shakes it madly, yelling "my dude have u tried monads!"

kitten emergency
Jan 13, 2008

get meow this wack-ass crystal prison

Bloody
Mar 3, 2013

whats wrong with c# events

raminasi
Jan 25, 2005

a last drink with no ice

Bloody posted:

whats wrong with c# events

the whole "sender" thing is done kinda dumb

before c# 6, having to either null-check or subscribe a dummy handler before firing was tedious, and the c# 6 fix involves kinda clunky syntax

Soricidus
Oct 21, 2010
freedom-hating statist shill

Slurps Mad Rips posted:

a man falls through the earth and into parisian catacombs. taking a torch from the wall he spies row upon row of skeletons. grasping the nearest by the shoulders, he shakes it madly, yelling "my dude have u tried monads!"

new deus ex sounding good

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

Slurps Mad Rips posted:

a man falls through the earth and into parisian catacombs. taking a torch from the wall he spies row upon row of skeletons. grasping the nearest by the shoulders, he shakes it madly, yelling "my dude have u tried monads!"

monads less problems

qntm
Jun 17, 2009

Soricidus posted:

new deus ex sounding good

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
<that thing you like> Considered Harmful :smug:

dick traceroute
Feb 24, 2010

Open the pod bay doors, Hal.
Grimey Drawer
your posts considered harmful

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord
"Posting Considered Harmful" would be a pro tier username

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

dick traceroute posted:

your posts considered harmful

guess you like his posts then

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
gently caress gently caress gently caress i just fixed my first lifetime issue by thoughtfully applying lifetime parameters without just doing what the compiler or google told me to do.

it's starting to make a little bit of sense

VikingofRock
Aug 24, 2008




MALE SHOEGAZE posted:

gently caress gently caress gently caress i just fixed my first lifetime issue by thoughtfully applying lifetime parameters without just doing what the compiler or google told me to do.

it's starting to make a little bit of sense

Noice :respek:

sarehu
Apr 20, 2007

(call/cc call/cc)
Rust is Software's Salvation

Swift folks plz add lifetimes and crush these retards.

triple sulk
Sep 17, 2014



you know it's funny that people poo poo on go but at least the go community has done useful things with it to date instead of just jerk off over how good their language is

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

sarehu posted:

Rust is Software's Salvation

Swift folks plz add lifetimes and crush these retards.

this guy is trying very actively trying to raise money for redox, so view this as dumb publicity (which it is) instead of someone's actual opinion

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.

MALE SHOEGAZE posted:

so view this as dumb publicity (which it is) instead of someone's actual opinion

most tech blog posts in a nutshell

gonadic io
Feb 16, 2011

>>=


one of the mods of /r/rust got fed up with all of those "lifetimes are like a burrito" posts

triple sulk
Sep 17, 2014



gonadic io posted:



one of the mods of /r/rust got fed up with all of those "lifetimes are like a burrito" posts

lmao

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

sarehu posted:

Rust is Software's Salvation

Swift folks plz add lifetimes and crush these retards.

we're not adding loving lifetime qualification, but we'll get 95% of the benefit for like 1% of the pain

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



i just looked up lifetimes and they look dumb as hell

Bloody
Mar 3, 2013

what are they

gonadic io
Feb 16, 2011

>>=
they're rust's way of stopping use-after-free. any reference to an object cannot outlive the object. the reference and the object have the same lifetime and the compiler makes sure that you can't use the ref after the object's lifetime is out of scope (i.e. the object has been destroyed)

Adbot
ADBOT LOVES YOU

gonadic io
Feb 16, 2011

>>=
it gets more complicated when you have subcomponents of objects etc.

the official tutorial is here: https://doc.rust-lang.org/book/lifetimes.html

but im not sure how much sense it'll make unless you 1) know rust's syntax, and 2) have gone through the tutorials on ownership and borrowing

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply