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
FamDav
Mar 29, 2008

fleshweasel posted:

doubtless there is some static method you need to look up to use for this relatively common case in programming

reminds me of NaN. NaN is so useless.

Nan's behavior is delightful when doing a bunch of number crunching on hole-filled data that you'd rather just run and then check for isNaN afterwards.

I remember some code I looked at that for some reason used -9999999 instead of NaN and would just check to see if the result value was negative because it should never be negative.

Adbot
ADBOT LOVES YOU

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...
the only horror there is returning nil if something isn't in the array i guess because

code:
irb(main):001:0> a = [nil]
=> [nil]
irb(main):002:0> a.include?(nil)
=> true

gonadic io
Feb 16, 2011

>>=
that literally is the problem, yeah.

[].first should not equal [nil].first

Notorious b.s.d.
Jan 25, 2003

by Reene
[].first should throw an exception.

FamDav
Mar 29, 2008

Notorious b.s.d. posted:

[].first should throw an exception.

looking through the docs im surprised array can actually throw an exception at all.

they should probably say "calling first on an empty array leads to UB" so spergs on stackoverflow can smugly respond to people asking why this abomination is allowed to occur.

ultramiraculous
Nov 12, 2003

"No..."
Grimey Drawer

Notorious b.s.d. posted:

[].first should throw an exception.

it should return an empty optional

gonadic io
Feb 16, 2011

>>=

ultramiraculous posted:

it should return an empty optional

eh the two are reasonably equivalent - one you have to check first and one you have to check afterwards. If you fail to do either check, you can get an exception.

(called head and listToMaybe respectively in Haskell)

gonadic io fucked around with this message at 22:15 on Aug 17, 2014

Notorious b.s.d.
Jan 25, 2003

by Reene

ultramiraculous posted:

it should return an empty optional

in general ruby's type system is so crude and little-used by consumers that i'm not sure option types really "fit"

this exists, and it kinda looks ok
https://github.com/ms-ati/rumonade

it is hard to imagine it being folded into the stdlib though

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

Notorious b.s.d. posted:

in general ruby's type system is so crude and little-used by consumers that i'm not sure option types really "fit"

this exists, and it kinda looks ok
https://github.com/ms-ati/rumonade

it is hard to imagine it being folded into the stdlib though

oh cool gonna mess with this

Notorious b.s.d. posted:

it is hard to imagine it being folded into the stdlib though
no but it could be injected

MononcQc
May 29, 2007

Notorious b.s.d. posted:

[].first should throw an exception.

[1,2].first should also return 2 according to people a few pages ago :bahgawd:

Brain Candy
May 18, 2006

shrughes is not people

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

Notorious b.s.d. posted:

[].first should throw an exception.

battle-hardened ruby veterans try to only use methods like [].fetch(0)

Notorious b.s.d.
Jan 25, 2003

by Reene

Symbolic Butt posted:

battle-hardened ruby veterans try to only use methods like [].fetch(0)

'fetch' sickens me because it indicates that the library authors knew that [].first == nil was the wrong behavior

they knew they hosed up and they left it broken because they probably already had five users or something

Cybernetic Vermin
Apr 18, 2005

i really like some cascading nulls (ideally typed) over exceptions for the most primitive operations. sure it loses some information, but it makes it a lot easier to reason about error conditions. the example problem of an array containing a literal null value in a position being indistiguishable from the position not existing i don't find so troubling though, one can just view arrays as being potentially non-contiguous (i.e. some position may be undefined)

a matter of taste though certainly, and ruby does plenty of other stuff really wrong (including but not limited to not really going all the way with nulls either, neither cascading them or using them consistently)

FamDav
Mar 29, 2008
ruby 3 should make like python 3 and have breaking changes that are generally for the best, occasionally for the worse, and see like no uptake because of it

ShadowHawk
Jun 25, 2000

CERTIFIED PRE OWNED TESLA OWNER

FamDav posted:

ruby 3 should make like python 3 and have breaking changes that are generally for the best, occasionally for the worse, and see like no uptake because of it
Eh, python3 is taking off faster than ipv6!

Notorious b.s.d.
Jan 25, 2003

by Reene

ShadowHawk posted:

Eh, python3 is taking off faster than ipv6!

check your ipv6 figures

poo poo has launched hard in 2014

tef
May 30, 2004

-> some l-system crap ->

Symbolic Butt posted:

battle-hardened ruby veterans try to only use methods like [].fetch(0)

ruby and php share a lot in common

- a sort of 'can do' attitude in response to errors or problems. just return nil, or in php's case a falsish item
- the easiest way to build up software is just treating it like one big program in one big file.

none of this poo poo surprises me any more. out of bounds indexing a list? no problem! redefining built in methods and objects on an ad-hoc basis? totally. php may have it's warts but at least it's the same warts everywhere. ruby on the other hand is a language wart toolkit.

Sapozhnik
Jan 2, 2005

Nap Ghost

Notorious b.s.d. posted:

check your ipv6 figures

poo poo has launched hard in 2014

like what?

other than chinese cellphones maybe

(tmobile has an ipv6 thing i think?)

tef
May 30, 2004

-> some l-system crap ->

FamDav posted:

ruby 3 should make like python 3 and have breaking changes that are generally for the best, occasionally for the worse, and see like no uptake because of it

ruby already breaks for minor versions. no-one cares.

to explain: there are two types of rails projects

- stuck. frozen in time because something massive has changed, but because everything is implicitly defined it's impossible to work out what needs to be changed easily.

- alive. expect to bundler install after each pull.

for the alive ones, dealing with ruby changes is easy. rails causes more issues than ruby breaking in minor versions. who cares, it's just the same old poo poo.

for the stuck ones, it's ok, upgrading rails or any of the dependencies will never happen, so you don't have to worry about them. besides, it'll get rewritten from scratch in node.js or go or whatever because of the bad experiences with rails.

ShadowHawk
Jun 25, 2000

CERTIFIED PRE OWNED TESLA OWNER

Notorious b.s.d. posted:

check your ipv6 figures

poo poo has launched hard in 2014
And there's a reasonable % of python3 code out there too. No one seems to be making new python2-only libraries, and the existing ones are (slowly) migrating. Sort of like how no one is building hardware that is ipv4 only.

tef
May 30, 2004

-> some l-system crap ->

ShadowHawk posted:

python 3 migration


DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

tef posted:

ruby on the other hand is a language wart toolkit.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Notorious b.s.d. posted:

check your ipv6 figures

poo poo has launched hard in 2014

Yeah, we have some v6-only clusters now. probably only a few thousand machines, but a lot of cross-datacenter traffic is v6 now as well.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
for instance, depending on where i am in our codebase, hash#store(key, value) will either return the hash, or the stored value

so
code:
["f","b","c","h"].inject({}){ |k,v| k.store(v,"butts")}

either returns: 
{"f"=>"butts", "b"=>"butts", "c"=>"butts", "h"=>"butts"}

or returns:
NoMethodError: undefined method `store' for "butts":String

tef
May 30, 2004

-> some l-system crap ->
ruby

Corla Plankun
May 8, 2007

improve the lives of everyone

MALE SHOEGAZE posted:

for instance, depending on where i am in our codebase, hash#store(key, value) will either return the hash, or the stored value

so
code:
["f","b","c","h"].inject({}){ |k,v| k.store(v,"butts")}

either returns: 
{"f"=>"butts", "b"=>"butts", "c"=>"butts", "h"=>"butts"}

or returns:
NoMethodError: undefined method `store' for "butts":String

i can't think of any reasons why that would be

do you have any idea why it does that?

Sweeper
Nov 29, 2007
The Joe Buck of Posting
Dinosaur Gum

Notorious b.s.d. posted:

check your ipv6 figures

poo poo has launched hard in 2014

lol, slowest migration ever no one is replacing all their ipv4 hardware/code until it breaks

Kathleen
Feb 26, 2013

Grimey Drawer
ruby is php for weeaboos

ahmeni
May 1, 2005

It's one continuous form where hardware and software function in perfect unison, creating a new generation of iPhone that's better by any measure.
Grimey Drawer
an old friend of mine is porting some old ROM MUD code from C to Python3 and most of it has been just a bunch of regex work to get things up and running and its been neat to dig through 30 year old tech files like this:

memory.txt posted:

Merc Release 2.1
Sunday 01 August 1993

Furey mec@shell.portal.com
Hatchet hatchet@uclink.berkeley.edu
Kahn michael@uclink.berkeley.edu



=== Memory Management Overview

Merc contains the following memory regions: run file memory; stack; string
space; and permanent space. The approximate sizes of these regions are:

Run file memory 300 k
Stack 20 k
String space 1020 k
Permanent space 1020 k
TOTAL 2360 k



=== Run File Memory

The merc executable file has about 256k of code, 8k of initialized data, and
32k of uninitialized data. This was measured on a Sun 4 running SunOS 4.1.3
with gcc version 2.3.3.

This size is small compared to the total size, and there is little you can do
to change it.



=== Stack

We have never measured stack usage, but estimate it's somewhere between 10k and
30k. Merc has a wide, shallow calling tree. The largest consumers of stack
memory are local buffers of size MAX_STRING_LENGTH.

If you port Merc to a machine with 64k or less of stack, you should instrument
your object code with stack-usage measurements. Most compilers for machines in
this range have an option to do this.



=== String Space and fread_string()

At boot time, the function fread_string() is used to read in ~-delimited
strings from area files. These strings are stored into string space. After
all of the area files are read in, string space is read-only for the duration
of the program.

String space is allocated once on bootup and is not expandable. As
distributed, Merc 2.1 uses 1024k of string space. You can lower or raise
this number by editing the value of 'MAX_STRING' in 'db.c'.

Duplicate strings are stored only once into string space; hashing is used to
achieve this. The hash code for a string is simply its length. Each string in
string space is prefaced with a backpointer to the previous string with the
same hash code. (Aliasing through a union is needed to read and write these
pointers, because they can start at any byte boundary, and thus are
misaligned).

When fread_string() reads a new string, it creates the string at the end of
string space. It then finds the first hash pointer for that length and follows
the thread of hash pointers, looking for an already existing string with the
same contents. Strings in the hash chain are checked newest-first, which
benefits from the usual construction of area files, where duplicates are
usually duplicates of something seen recently.

If fread_string() finds that the new string is a duplicate, it simply discards
the new string and returns a pointer to the existing string. If the string is
new, it leaves it at the end of string space, fills in the new hash pointers,
and returns the new string.

After area-file loading is over, fread_string is also used to read player
files. In this case, new strings are not appended to string space, but instead
are simply handed to str_dup(). Thus the amount of string space used is fixed
at area-file loading time.

The functions str_dup() and free_string() take advantage of string space. If a
string being duplicated is in string space, str_dup() simply returns the same
pointer. If a string being freed is in string space, free_string() simply does
nothing. This strategy not only saves megabytes of memory through string
re-use, but also saves processor time as well.

Thus a cheap method is needed for deciding whether a given string is in string
space. This is one reason why strings are stored in one contiguous region of
size MAX_STRING. (The hash chains, however, would still work with
noncontiguous allocation).

Collecting all strings into one region has another advantage: locality of
reference. Most strings are unused most of the time. Because they are not
interspersed with other dynamically allocated memory, a virtual memory
operating system can page out almost all of the string space without affecting
performance.

After boot time the unused end of string space is wasted. This amounts to
about 160k in Merc 2.1. On a VM system this space is unused space is paged
out quickly, so it doesn't hurt to leave it alone. However, you can recover
this space easily by lowering MAX_STRING. If perchance you set MAX_STRING too
low you will get a boot-time error, but never any operational errors.

If you add a lot of areas you may need to increase MAX_STRING. Again, Merc
will tell you when you've run out.



=== Permanent space

This space holds everything else: all of the area file non-string data; all of
the created mobiles and objects; descriptor and player character structures;
you name it.

This space is dynamically allocated from calloc() in large blocks, which are
carved up and handed out as needed by alloc_perm(). As distributed, Merc 2.1
uses about 1024k of permanent space.

Unlike string space, permanent space grows on demand; alloc_perm() calloc's and
carves up as many blocks as needed as the game runs.

You can adjust the block size by changing MAX_PERM_BLOCK in 'db.c'. Adjustment
will have only a minor effect on space and time usage. If you port Merc to a
new system with a 64k or 32k limit on calloc() size, you could simply change
MAX_PERM_BLOCK to the largest calloc'able block on your system.

Merc never calls free() to return memory. Instead, memory is recycled for
future use. This has two advantages: it's faster to recycle a block than to
call free(), and it's faster to allocate a block from a free list than to
allocate one from calloc() or alloc_perm(). Most of the structure types have
their own free lists: char_free, obj_free, affect_free, et cetera.

Variable-sized blocks don't fit the per-structure-type free-list model. The
functions alloc_mem() and free_mem() manage blocks of arbitrary size. They
actually work by maintaining fixed-size lists for just a few supported sizes
and rounding requests up to a supported size. This is extremely fast; because
there are so few variable-sized blocks, the space penalty is inconsequential.

Brain Candy
May 18, 2006

ahmeni posted:

memory.txt posted:

The hash code for a string is simply its length

so much careful memory janitoring and then there's that

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

quote:

The hash code for a string is simply its length.

ah, that's where Rasmus got the idea for PHP function-name hashing, then. mystery solved.

Careful Drums
Oct 30, 2007

by FactsAreUseless

Notorious b.s.d. posted:

this except unironically

unlike amazon free tier microsoft isn't requiring you to give them a credit card number or anything. it's only for 30 days but it's really, truly free in that 30 days.

azure owns so hard it is the easiest thing ever

Soricidus
Oct 21, 2010
freedom-hating statist shill

Careful Drums posted:

azure owns so hard it is the easiest thing ever
no pain no gain

akadajet
Sep 14, 2003

beep! beep! quality programmer coming through.

Lyon
Apr 17, 2003

akadajet posted:

beep! beep! quality programmer coming through.


haha holy poo poo that is fantastic, I'm going to get a really esoteric pep to be the smuggest python license plater.

ahmeni
May 1, 2005

It's one continuous form where hardware and software function in perfect unison, creating a new generation of iPhone that's better by any measure.
Grimey Drawer

Lyon posted:

haha holy poo poo that is fantastic, I'm going to get a really esoteric pep to be the smuggest python license plater.

pep 435, the birth of the Enum :allears:

ultramiraculous
Nov 12, 2003

"No..."
Grimey Drawer

Brain Candy posted:

so much careful memory janitoring and then there's that

i don't even get why. i mean if you're splitting the strings with a delimiter, you're reading through the whole thing. can you not even right a dumb/bad hash algo that uses maybe the length and the sum of the chars scanned over or something?

ahmeni
May 1, 2005

It's one continuous form where hardware and software function in perfect unison, creating a new generation of iPhone that's better by any measure.
Grimey Drawer

ultramiraculous posted:

i don't even get why. i mean if you're splitting the strings with a delimiter, you're reading through the whole thing. can you not even right a dumb/bad hash algo that uses maybe the length and the sum of the chars scanned over or something?

muds have always been an amazing showcase of technical decisions that will fall to pieces if one character is out of place anywhere, cobbled together by grognards turned programmer

Adbot
ADBOT LOVES YOU

pseudopresence
Mar 3, 2005

I want to get online...
I need a computer!
I propose we get rid of indexing entirely, to be replaced with the infix operator th:

nthusers

That way the lefthand argument is unambiguously ordinal.

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