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
Bongo Bill
Jan 17, 2012

Also, smash the state.

No, that's wrong. Smash state.

Adbot
ADBOT LOVES YOU

vOv
Feb 8, 2014

Foxfire_ posted:

code:
int foo()
{
  int x = 0;
  return (x = 1) + (x = 2);
}
code:
def bar():
  x = []
  return x.append(1) + x.append(2)
Only real difference is that C doesn't specify an order to its + operator and Python does. :shrug:

The difference is that it'd be legal for the C program to format your hard drive because it's undefined behavior, not just implementation-specified, but not for the Python program to do so

Jeb Bush 2012
Apr 4, 2007

A mathematician, like a painter or poet, is a maker of patterns. If his patterns are more permanent than theirs, it is because they are made with ideas.
any project as large as CPython probably has undefined behaviour lurking somewhere, so the interpreter might just decide to format your hard drive anyway

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde

Foxfire_ posted:

Only real difference is that C doesn't specify an order to its + operator and Python does. :shrug:
That's what happens when you standardize a language on paper for which multiple implementations already exist, rather than one holy reference implementation.

KernelSlanders
May 27, 2013

Rogue operating systems on occasion spread lies and rumors about me.
If you made your lists immutable none of this would be an issue.

Python code:
def bar():
  x = []
  return x.append(1) + x.append(2)
x.append(1) can return [1] and not modify x. If so, this resolves very simply to [1] + [2] or [1,2].

I don't want to be religious about the no side effects thing. Imperative programming is fine too, but constructs like this that both modify and return are trying to have it both ways and just asking for trouble. Why should x.append(1) return anything?

KernelSlanders fucked around with this message at 03:44 on Sep 9, 2017

Suspicious Dish
Sep 24, 2011

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

KernelSlanders posted:

Why should x.append(1) return anything?

It doesn't.

KernelSlanders
May 27, 2013

Rogue operating systems on occasion spread lies and rumors about me.

heh, that's what i get for replying to a post without evaluating it critically I guess

Foxfire_
Nov 8, 2010

and that's what I get for writing examples while tired without running them

everybody pretend I wrote this instead please

code:
def foo():
  x = [1,2]
  return x.pop() - x.pop()

FoiledAgain
May 6, 2007

KernelSlanders posted:

Why should x.append(1) return anything?

It does return something. It returns None.

Zemyla
Aug 6, 2008

I'll take her off your hands. Pleasure doing business with you!
This is where Haskell shows its superiority. The operations with potential side effects live in the IO monad, so they have to be explicitly sequenced, and thus cannot have an undefined or implementation-dependent evaluation order.

Linear Zoetrope
Nov 28, 2011

A hero must cook

Zemyla posted:

This is where Haskell shows its superiority. The operations with potential side effects live in the IO monad, so they have to be explicitly sequenced, and thus cannot have an undefined or implementation-dependent evaluation order.

Comedy response: until you call FFI C code

PhantomOfTheCopier
Aug 13, 2008

Pikabooze!

FoiledAgain posted:

It returns None.
Python None is indeed a coding horror.

Athas
Aug 6, 2007

fuck that joker

Zemyla posted:

This is where Haskell shows its superiority. The operations with potential side effects live in the IO monad, so they have to be explicitly sequenced, and thus cannot have an undefined or implementation-dependent evaluation order.

What is the result of
code:
undefined + error "farts"
? The Haskell trick only works if you state that different ways of diverging should not be distinguished.

VikingofRock
Aug 24, 2008




Zemyla posted:

This is where Haskell shows its superiority. The operations with potential side effects live in the IO monad, so they have to be explicitly sequenced, and thus cannot have an undefined or implementation-dependent evaluation order.

Wait, but isn't the evaluation order still really important in Haskell because of how laziness works? For example it's important that && evaluates its first argument first, so that if you evaluate false && some_expensive_predicate then some_expensive_predicate isn't evaluated.

Athas
Aug 6, 2007

fuck that joker

VikingofRock posted:

Wait, but isn't the evaluation order still really important in Haskell because of how laziness works? For example it's important that && evaluates its first argument first, so that if you evaluate false && some_expensive_predicate then some_expensive_predicate isn't evaluated.

Since && is a library function, this is entirely up to how you do the pattern matching. For example, this definition would not be short-circuiting:

code:
True && True = True
True && False = False
False && False = False
False && True = False
But this one is, because it does not always inspect its right argument:

code:
True && True = True
False && _ = False
The issue occurs for the few primitives that are built into the language, like addition of Ints. I have been programming Haskell for eight years and I don't really know the answer to that one.

Zemyla
Aug 6, 2008

I'll take her off your hands. Pleasure doing business with you!

Linear Zoetrope posted:

Comedy response: until you call FFI C code

Non-comedy response: FFI C code should have its signature return an IO value if it is impure.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Hey, it's that time again!

Nothing quite like sprinkling an existing data interchange format with a generous helping of new features. It's irresistable!

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
The lack of trailing commas in JSON is a legit complaint. Comments, unquoted keys, and the other stuff aren't nearly as irritating, and IIRC there are good reasons to not support comments (though I forget what they are).

Given that, I'm still not dumb enough to try to make a new version of a standard, especially a non-backwards-compatible one.

KernelSlanders
May 27, 2013

Rogue operating systems on occasion spread lies and rumors about me.
Within a particular schema comments can be added trivially by simply ignoring a particular key. I'm fond of "//".

code:
{
  "my_list": [1, 2, 3],
  "my_text": "Hello, world!",
  "//": "This is a comment and will be ignored by the application, because I wrote the application to ignore it"
}

Steve French
Sep 8, 2003

KernelSlanders posted:

Within a particular schema comments can be added trivially by simply ignoring a particular key. I'm fond of "//".

code:

{
  "my_list": [1, 2, 3],
  "my_text": "Hello, world!",
  "//": "This is a comment and will be ignored by the application, because I wrote the application to ignore it"
}

What's the use case there, though? Comments only seem helpful to me in say config files, and there I'd rather change my application to use a parser that handles some JSON variant that allows comments (we use HOCON), than have to write custom logic to handle special keys in any arbitrary object, while severely limiting the number and location of comments. Perhaps there's something else I'm missing?

KernelSlanders
May 27, 2013

Rogue operating systems on occasion spread lies and rumors about me.
My two principle use cases are config files (although I too will use HOCON when I can) and annotating JSON unit test fixtures.

Sedro
Dec 31, 2008
JSON is fine for what it is, and HOCON is really good for config files that people will edit. Just not YAML, anything but YAML

NihilCredo
Jun 6, 2011

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

Sedro posted:

JSON is fine for what it is, and HOCON is really good for config files that people will edit. Just not YAML, anything but YAML

lol. literally the only thing that matters to me as a dev is that I'm way more likely to have a Yaml deserialization library available than a hocon one

meanwhile as a user, hocon still has braces and commas and poo poo, so I'd much rather edit yaml, tyvm. if you're worried i might be an rear end in a top hat and do the weird corner case stuff you can find in the yaml spec, then toml is an acceptable substitute

PhantomOfTheCopier
Aug 13, 2008

Pikabooze!
Durr
code:
{
  "key that matters A":  "value",
  "key that matters B":  "value",
  "comment with historical relevance":  "yay I'm ignored because why would anyone use this key?",
  "LOAD ME!":  "oh darn no one ever will"
}
Yay, comments are free. But the trailing comma thing, yeah, that's beyond ridiculous. Any language that can't parse ,} as a non-element on input, this is why we see leading commas.

And YAML... I've had to work on an application where someone decided to use it as a configuration format. It's a complete pain. The spacing is just about as ridiculous as Python's inability to understand program grouping, and it's really cute when the YAML parses beautifully and successfully until it's passed to Python where there's a bunch of parse errors because PyYAML gets confused (at least I seem to recall that's the module that was being used). Then one day I was using abbreviations only to find out that the app designer choose YAML despite the transport mechanism being SOAP (there's another horror story, I suppose), and it doesn't pass data unmodified because it's XML. Woohoo, let's blast all the ampersands! (on the way in but not on the way out)

Myself, I'm still partial to ASCII 0x1c--0x1f.

PhantomOfTheCopier fucked around with this message at 10:08 on Sep 10, 2017

SupSuper
Apr 8, 2009

At the Heart of the city is an Alien horror, so vile and so powerful that not even death can claim it.
We should start classifying data formats as "human-writable" instead of "human-readable". Because every plain-text data format is human-readable, but users will gently caress up anything that's not as basic as an INI file.

Vanadium
Jan 8, 2005

I wish all my config files were .nix!

Stop the .toml madness!

pseudorandom name
May 6, 2007

XML isn't human readable. :colbert:

Pollyanna
Mar 5, 2005

Milk's on them.


Ranzear posted:

There was probably some debug logging stuffed in there at one point.

You could just do this in that case:

code:
            if (responseJSON == null)  // assuming you're checking specifically for the null case and not for just plain falsiness
            {
                console.log("gently caress")
            }

            return responseJSON;

Soricidus
Oct 21, 2010
freedom-hating statist shill

pseudorandom name posted:

XML isn't human readable. :colbert:

<butt size="fat" scent="foul"/> ? Unreadable garbage fit only for robots. But {"butt":{"size":"fat","scent":"foul"}} is good and very human friendly.

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Internet Janitor posted:

Hey, it's that time again!

Nothing quite like sprinkling an existing data interchange format with a generous helping of new features. It's irresistable!

Man, I saw that first sentence and immediately thought "oh gently caress," but I actually did cook up something that works exactly like the handlers parameter in JSON plus for a project a few years ago, I guess I should've made it a standalone library.

Ellie Crabcakes
Feb 1, 2008

Stop emailing my boyfriend Gay Crungus

TooMuchAbstraction posted:

The lack of trailing commas in JSON is a legit complaint. Comments, unquoted keys, and the other stuff aren't nearly as irritating, and IIRC there are good reasons to not support comments (though I forget what they are)
Because it's an interchange format for relatively simple data structures. Using it as a primary config format or concatenating it is silly and will bite you in the rear end. There are even better interchange formats.

Except YAML. YAML sucks balls.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


Vanadium posted:

I wish all my config files were .nix!

Stop the .toml madness!

You may want to look into dhall, a typed, functional, total language with a toNix converter. Actually, I think I've heard it grew from a project of adding types to nix?

I'm still not sure 100% if this is a horror, but weirdly, it can also import expressions by url, and its prelude is hosted on ipfs.

code:
$ dhall
let not = [url]https://ipfs.io/ipfs/QmQ8w5PLcsNz56dMvRtq54vbuPe9cNnCCUXAQp6xLc6Ccx/Prelude/Bool/not[/url]
in  not True
<Ctrl-D>
Bool

False
e: pretend those auto-added [url] tags are not there

QuarkJets
Sep 8, 2008

always define your own human-readable data containers and don't tell anyone else how they work

JawnV6
Jul 4, 2004

So hot ...

QuarkJets posted:

always define your own human-readable data containers and don't tell anyone else how they work

Adjust the value of "human" as appropriate

QuarkJets
Sep 8, 2008

I usually encode data so that it's readable by dogs

PhantomOfTheCopier
Aug 13, 2008

Pikabooze!

QuarkJets posted:

always define your own human-readable data containers and don't tell anyone else how they work
There is nothing better than Data:: Dumper. If it's not quite clean enough for you, I recommend Acme::Bleach.

Ellie Crabcakes
Feb 1, 2008

Stop emailing my boyfriend Gay Crungus

PhantomOfTheCopier posted:

There is nothing better than Data:: Dumper.
:nono:

quote:

If it's not quite clean enough for you, I recommend Acme::Bleach.
Now we're talking.

KernelSlanders
May 27, 2013

Rogue operating systems on occasion spread lies and rumors about me.
Maybe the constraints on data interchange formats and config file formats are sufficiently different that they deserve two different file formats?

:shrug:

Absurd Alhazred
Mar 27, 2010

by Athanatos

KernelSlanders posted:

Maybe the constraints on data interchange formats and config file formats are sufficiently different that they deserve two different file formats?

:shrug:

Config files are just serialized behavior, though. :shrug:

Adbot
ADBOT LOVES YOU

Steve French
Sep 8, 2003

Absurd Alhazred posted:

Config files are just serialized behavior, though. :shrug:

So are files containing code, both as written by humans and compiled code.

So let's just use JSON for everything!

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