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
NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Suspicious Dish posted:

Paraphrased in JS, the code (in a third-party library) was roughly:

JavaScript code:
function parseQS(query) {
    let S = '{';
    query.split('&').forEach((item) => {
        let [k, v] = item.split('=');
        S += JSON.stringify(k);
        S += ': ';
        S += JSON.stringify(v);
        S += ', ';
    });
    S = S.slice(0, -2);
    S += '}';
    return S;
}

Ah, the COBOL programmer's serialiser. Welp, never mind.

Adbot
ADBOT LOVES YOU

Klades
Sep 8, 2011

canis minor posted:

SO, please never change

code:
Sweet baby jesus

I... this... why?
Why does that switch work. Does it work?
Why does he assign replace to num and return num instead of returning replace?
gently caress.
I don't even know why I'm reacting to strongly to this.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Klades posted:

I... this... why?
Why does that switch work. Does it work?
Why does he assign replace to num and return num instead of returning replace?
gently caress.
I don't even know why I'm reacting to strongly to this.

when you say, "does it work?" do you mean can you do that in Javascript and does it do what it looks like it does, or do you mean "does this code do what it purports to do"?

to the first one, the answer is "i dunno. probably", to the second one the answer is "no": https://jsfiddle.net/62dpqsqn/ (take a look at 105) (function "out()" is from [url="https://"http://stackoverflow.com/questions/17382200/print-var-in-jsfiddle"]here[/url])

BigRedDot
Mar 6, 2008

As long as we are bitching about JSON:

* not supporting nan or inf
* making a trailing comma after the last element of a sequence an error

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe


(seen on imgur)

MrMoo
Sep 14, 2000

BigRedDot posted:

As long as we are bitching about JSON:

* not supporting nan or inf

It's bad enough JS treats numbers as double precision floating points it is crazy to pass the floating point special values over to real numbers too: -0, (q/s) NaN, +∞ , −∞.

I guess you can abuse things using Number.NEGATIVE_INFINITY, Number.NaN, etc, I'm sure more than one library does already.

MrMoo fucked around with this message at 02:57 on Nov 1, 2016

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

the real horror is using mongodb

wide stance
Jan 28, 2011

If there's more than one way to do a job, and one of those ways will result in disaster, then he will do it that way.
Comments not essays.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Hammerite posted:

when you say, "does it work?" do you mean can you do that in Javascript and does it do what it looks like it does, or do you mean "does this code do what it purports to do"?

to the first one, the answer is "i dunno. probably", to the second one the answer is "no": https://jsfiddle.net/62dpqsqn/ (take a look at 105) (function "out()" is from [url="https://"http://stackoverflow.com/questions/17382200/print-var-in-jsfiddle"]here[/url])

I've just realised that it also renders 99 as "XCIX", which is longer than the equivalent "IC"

foxy boxing babe
Jan 17, 2010


code:
function sleep(m){
    var n = new Date().getTime();
    for (var i = 0; i < 1e7; i++){
        if ((new Date().getTime() - n) > m){
            break;
        }
    }
}
:dogbutton:

foxy boxing babe fucked around with this message at 03:32 on Nov 2, 2016

BigRedDot
Mar 6, 2008

MrMoo posted:

It's bad enough JS treats numbers as double precision floating points it is crazy to pass the floating point special values over to real numbers too: -0, (q/s) NaN, +∞ , −∞.

Agree to disagree I guess. I work on a cross language data vis platform where people start with data that has NaN's all the time, and JSON's lack of any good (efficient) way to get them from language A to language B is a pain the rear end and a stupid, stupid oversight from where I am sitting.

xtal
Jan 9, 2011

by Fluffdaddy
This post was wrong but JavaScript and json still suck.

xtal fucked around with this message at 19:03 on Nov 1, 2016

MrMoo
Sep 14, 2000

I think you gain on flexibility by punting special values to just a string, i.e. "NaN" rather than forcing extra flags everywhere in the codec.

The R language has the wonderful constant NA which is quite useful but does not translate to anything else well. FYI: null is an empty object, NA is a missing object.

MrMoo fucked around with this message at 19:04 on Nov 1, 2016

Bonfire Lit
Jul 9, 2008

If you're one of the sinners who caused this please unfriend me now.

xtal posted:

What other languages have NaN so I can know not to use them?
All of the ones that use IEEE754 floats. Which includes basically every single language in wide-spread use.

xtal
Jan 9, 2011

by Fluffdaddy

Bonfire Lit posted:

All of the ones that use IEEE754 floats. Which includes basically every single language in wide-spread use.

I noticed my misunderstanding after I posted it, I just haven't had to deal with or think about NaN in like 5 years

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Hammerite posted:

I've just realised that it also renders 99 as "XCIX", which is longer than the equivalent "IC"

XCIX is correct. In Roman numerals, you're not supposed to subtract a number from a number that's more than 10 times greater. That's why 1999 is MCMXCIX instead of MIM.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

DaTroof posted:

XCIX is correct. In Roman numerals, you're not supposed to subtract a number from a number that's more than 10 times greater. That's why 1999 is MCMXCIX instead of MIM.

Oh poo poo. Well before this I had a favourable opinion of roman numerals, and now I think they're some bullshit

boo_radley
Dec 30, 2005

Politeness costs nothing

Hammerite posted:

Oh poo poo. Well before this I had a favourable opinion of roman numerals, and now I think they're some bullshit

You're not wrong.

xtal
Jan 9, 2011

by Fluffdaddy
Today I learned I don't like Roman numerals

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



DaTroof posted:

XCIX is correct. In Roman numerals, you're not supposed to subtract a number from a number that's more than 10 times greater. That's why 1999 is MCMXCIX instead of MIM.

JFC no wonder they didn't invent algebra - they spent so much time figuring out what numbers looked like they didn't have the mental energy to spare.

Joda
Apr 24, 2010

When I'm off, I just like to really let go and have fun, y'know?

Fun Shoe
Were numerals actually used for anything other than official purposes? Vertical lines on a slab of stone/in the sand/whatever would be preferable to roman numerals for anything approaching arithmetic.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

Joda posted:

Were numerals actually used for anything other than official purposes? Vertical lines on a slab of stone/in the sand/whatever would be preferable to roman numerals for anything approaching arithmetic.

How do you define "official purposes"? Someone has to keep the accounting books for any non-trivial business, for example. It's not government work but it's definitely important.

Joda
Apr 24, 2010

When I'm off, I just like to really let go and have fun, y'know?

Fun Shoe

TooMuchAbstraction posted:

How do you define "official purposes"? Someone has to keep the accounting books for any non-trivial business, for example. It's not government work but it's definitely important.

Simply official documents. Like final results of accounting or resource tallies, for instance. I'd imagine doing the arithmetic of adding all those things up would take much more time if you had to accomodate an over-complicated number system as well, but that won't stop you from translating the final result.

fishmech
Jul 16, 2006

by VideoGames
Salad Prong

Joda posted:

Were numerals actually used for anything other than official purposes? Vertical lines on a slab of stone/in the sand/whatever would be preferable to roman numerals for anything approaching arithmetic.

Do you really think etching out 81 vertical lines is less effort than writing LXXXI?

The "normal letters are also our numbers" system can be seen in various languages for thousands of years. Even if it was clunky compared to modern place-value numerals, it was still the thing you'd have to use for anything particularly large.

xzzy
Mar 5, 2009

I've never looked up what archaeologists have to say about the development of roman numerals, but I always figured it was the formalization of people making tick marks in the dirt while taking inventory of a thing.

I figured "IV" standing for four was even some basic arithmetic, like Mr. Bureaucrat has five pairs of shoes marked down then someone comes by and takes a pair and is "all gently caress I just wrote that V and I don't feel like erasing and starting over, so I'll just put a I in front of it to indicate one is missing."

Athas
Aug 6, 2007

fuck that joker
As far as I understand it, the Romans didn't use the notation where you subtracted smaller numerals from following larger numerals. The order didn't matter, and you just added it all up. This makes addition trivial, and even subtraction's not too bad - and you can always simplify at the end.

fishmech
Jul 16, 2006

by VideoGames
Salad Prong
This is what the corresponding Greek system looked like:

If you're familiar with the alphabet, you'll notice that the first couple numbers are equivalent to saying A=1, B=2 etc. Ancient Hebrew (and modern Hebrew, though like the modern Greeks you'd only use this way to make a statement rather than day to day number writing) worked similar.


The Roman system's really a bit more advanced, in that they reduced the number of different letters they'd use to write numbers.

Athas posted:

As far as I understand it, the Romans didn't use the notation where you subtracted smaller numerals from following larger numerals. The order didn't matter, and you just added it all up. This makes addition trivial, and even subtraction's not too bad - and you can always simplify at the end.

That depended on time and usage. You'd be more likely to use the formal system with subtractions if you were writing a final version of something, even if you'd used just the addition system for your first couple drafts.

The subtraction system could also be a lot more compact for certain values.

Keep in mind that for doing actual calculations, a lot of the time you'd be working with some form of abacus rather than writing all the stuff down too.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
https://github.com/const-io/max-uint32

somehow this npm package has 9 dependencies and tests

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost
It looks like literally all of those dependencies are to test that constant across a range of browsers. Maybe the point of the package is to show the horror that is JS?

Soricidus
Oct 21, 2010
freedom-hating statist shill

Suspicious Dish posted:

https://github.com/const-io/max-uint32

somehow this npm package has 9 dependencies and tests

you forgot to mention the other 50-odd modules that the same author has written to define other numbers

i think i'm https://github.com/const-io/cbrt-eps-float64

i'm also disappointed that https://github.com/const-io/zero, https://github.com/const-io/one, etc. do not exist. this cannot be good software engineering practice.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
code:
'use strict';

// EXPORTS //

module.exports = 4294967295; // 2**32 - 1

quote:

Copyright © 2015-2016. The Compute.io Authors.

necrotic
Aug 2, 2005
I owe my brother big time for this!
https://github.com/const-io/numeric-constants/blob/master/lib/index.js might be the best one.

VikingofRock
Aug 24, 2008




Suspicious Dish posted:

https://github.com/const-io/max-uint32

somehow this npm package has 9 dependencies and tests

I might be reading this wrong, but aren't those all dev dependencies?

Still, Jesus Christ.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

https://github.com/const-io/pi/blob/master/lib/index.js
https://github.com/const-io/pi/blob/master/test/test.js

this is the contender for the best imo. they include a bunch of numbers that they can't even use.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
These illustrate a fascinating interpretation of what it means to "test" software.

vOv
Feb 8, 2014

How the hell would you even test a module that just exports pi?

Edison was a dick
Apr 3, 2010

direct current :roboluv: only

vOv posted:

How the hell would you even test a module that just exports pi?

Compare it against another module that also exports PI, or do a bunch of calculations with known results with a correct PI and substitute the value of PI from this module in and check that it's got the correct result.

qntm
Jun 17, 2009
The other day at work I found we were using this module to create a new object with only some of the keys of the old object. This module has a total of 40 dependencies spanning 200 files and taking up nearly 1MB on disk - not dev dependencies, just regular dependencies. Figuring out exactly what this code does is a long, very tedious trawl through acres of code which do almost nothing but pull in other microdependencies. All of this person's code is like this.

I scrapped it in favour of a four-line loop.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

vOv posted:

How the hell would you even test a module that just exports pi?

You stop pretending that all code needs to be tested.

Adbot
ADBOT LOVES YOU

canis minor
May 4, 2011

qntm posted:

The other day at work I found we were using this module to create a new object with only some of the keys of the old object. This module has a total of 40 dependencies spanning 200 files and taking up nearly 1MB on disk - not dev dependencies, just regular dependencies. Figuring out exactly what this code does is a long, very tedious trawl through acres of code which do almost nothing but pull in other microdependencies. All of this person's code is like this.

I scrapped it in favour of a four-line loop.

I'm trying to understand why somebody felt the need to put glob matching into a language that supports regex

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