|
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 |
# ? Dec 28, 2016 06:20 |
|
|
# ? Jun 4, 2024 16:47 |
|
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!
|
# ? Dec 28, 2016 06:23 |
|
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 |
# ? Dec 28, 2016 06:25 |
|
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.
|
# ? Dec 28, 2016 06:27 |
|
nobody mention cache misses or page faults
|
# ? Dec 28, 2016 07:35 |
|
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? 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.
|
# ? Dec 28, 2016 09:55 |
|
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. 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 |
# ? Dec 28, 2016 10:33 |
|
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? a pointer to Car counts as a "primitive" now?
|
# ? Dec 28, 2016 10:43 |
|
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
|
# ? Dec 28, 2016 10:59 |
|
Fergus Mac Roich posted:Non-rhetorical question for you: what do you mean? 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:
|
# ? Dec 28, 2016 15:03 |
|
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. <- 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 |
# ? Dec 28, 2016 15:09 |
|
who keeps yelling OPTION TYPES at my house. show yourself coward i will never use option types
|
# ? Dec 28, 2016 19:38 |
|
my friend, have you considered that option types are an example of a monad
|
# ? Dec 28, 2016 19:53 |
|
* a heckler in the audience * c# events are convoluted and bad!
|
# ? Dec 28, 2016 19:55 |
|
BiohazrD posted:* a correct opinion-haver in the audience who's about to get shaggared *
|
# ? Dec 28, 2016 20:43 |
|
they're good but could be better
|
# ? Dec 28, 2016 20:45 |
|
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!"
|
# ? Dec 28, 2016 20:46 |
|
|
# ? Dec 28, 2016 20:56 |
|
whats wrong with c# events
|
# ? Dec 28, 2016 21:21 |
|
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
|
# ? Dec 28, 2016 21:35 |
|
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
|
# ? Dec 29, 2016 00:52 |
|
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
|
# ? Dec 29, 2016 02:07 |
|
Soricidus posted:new deus ex sounding good
|
# ? Dec 29, 2016 10:14 |
|
<that thing you like> Considered Harmful
|
# ? Dec 29, 2016 14:00 |
|
your posts considered harmful
|
# ? Dec 29, 2016 14:41 |
|
"Posting Considered Harmful" would be a pro tier username
|
# ? Dec 29, 2016 14:48 |
|
dick traceroute posted:your posts considered harmful guess you like his posts then
|
# ? Dec 29, 2016 22:53 |
|
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
|
# ? Dec 29, 2016 23:14 |
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. Noice
|
|
# ? Dec 29, 2016 23:21 |
|
Rust is Software's Salvation Swift folks plz add lifetimes and crush these retards.
|
# ? Dec 30, 2016 00:18 |
|
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
|
# ? Dec 30, 2016 00:47 |
|
sarehu posted:Rust is Software's Salvation 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
|
# ? Dec 30, 2016 00:57 |
|
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
|
# ? Dec 30, 2016 01:34 |
|
one of the mods of /r/rust got fed up with all of those "lifetimes are like a burrito" posts
|
# ? Dec 30, 2016 01:36 |
|
gonadic io posted:
lmao
|
# ? Dec 30, 2016 01:46 |
|
sarehu posted:Rust is Software's Salvation we're not adding loving lifetime qualification, but we'll get 95% of the benefit for like 1% of the pain
|
# ? Dec 30, 2016 06:04 |
|
i just looked up lifetimes and they look dumb as hell
|
# ? Dec 30, 2016 19:11 |
|
what are they
|
# ? Dec 30, 2016 19:27 |
|
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)
|
# ? Dec 30, 2016 19:36 |
|
|
# ? Jun 4, 2024 16:47 |
|
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
|
# ? Dec 30, 2016 19:38 |