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
KaneTW
Dec 2, 2011

Because it's unneeded in a data format designed for data interchange.

Adbot
ADBOT LOVES YOU

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.

Golbez posted:

I'm an idiot, so what is bad about this? That he didn't know why he was adding it?

It's cargo cult as gently caress to just add in features without having a use case.

Zamujasa
Oct 27, 2010



Bread Liar

KaneTW posted:

Because it's unneeded in a data format designed for data interchange.

I could see it being useful if you were using a number for bitmasks, since JSON is rather readable as it is. (A lot more so than some other interchange formats, that's for sure.)



Also, the Russian Wonder brought us a new delivery today. We now have another 3 tables for the three columns on another page. But he listened, now there's a useful jQuery widget that makes adding a HTML link to one of the 37 text fields a little easier! :allears:

Simulated
Sep 28, 2001
Lowtax giveth, and Lowtax taketh away.
College Slice
Why is having a machine-readable way to document data interchange (whether XML schema or the proposed JSON schema) a bad idea?

Without this it makes it really difficult to write tools to interact with these APIs, relying on the programmer to read the doc and code it all by hand. I wish I could point a tool to a URL and have it materialize classes matching the JSON data structure, complete with enums for flags, etc. Thats one of the few good things about the WebService/WS way. Just point at the WSDL URL and any modern tool can spit out all the boilerplate easily. My objection to XML is how drat complicated it is, not the idea in general.

It does make me wonder... Would an HTTP HELP verb serve such a purpose? Instead of everyone coming up with their own API doc format, could you figure out some way to support it directly? I havent really thought this through so there may be some good reasons against it, but I like the idea of some standard machine-readable way to communicate about APIs and data structures.


As an aside, it seems like people who only ever deal with twitter-esque services are the ones who never see the need for anything even a little bit complicated. Not everything in the world is a simple picture upload or blog post, sometimes you have to support really complex things like 850 telephone service orders or student school records that require precision and/or complex amounts of data in complex relationships. Edit: which are a massive bitch to code by hand.

Strong Sauce
Jul 2, 2003

You know I am not really your father.





The whole point of JSON was to be more lightweight than XML, I'm against anything that is going to signficantly bloat JSON libraries or its underlying structure. That said, just give me JSON + a way to handle binary blob data well. If implementing hexadecimals allows this to happen, so be it. But I guess what I want is just JSON+BSON.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Strong Sauce: You could use an array of integer values in decimal notation just as easily as an array of integers in hexadecimal notation- the additional number formats confer no greater expressive power and serve only to make the standard more complex.

In the context of having a semi- human-readable text format for data interchange it would probably make the most sense to base64 encode your binary blobs and put them in a JSON string, anyway.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Just use XML if you need the complex things that have already been implemented for XML. There's no point in completely reinventing everything just for a simpler syntax when the syntax doesn't even fit your needs.

epswing
Nov 4, 2003

Soiled Meat

Strong Sauce posted:

just give me JSON + a way to handle binary blob data well

Can't you just base64 your binary data?

E: :argh:

Zombywuf
Mar 29, 2008

What you guys need is MIME.

xf86enodev
Mar 27, 2010

dis catte!

Ender.uNF posted:

relying on the programmer to read the doc and code it all by hand

This isn't directed at you but seriously it screams :effort:
But this is what's wrong with the hacking superstar coder culture these days.

Read the loving manual and don't reinvent the loving wheel.

There are probably at least a dozen "tools" on github that are supposed to overcome problems that could be solved by actually just "interacting" with your peers.

Read the docs your coworkers left you, ask them stuff you don't understand, just make the loving phone call that'll take 10 minutes out of your reddit-browsing-time.

Maybe your ego tells you otherwise but you're not above it all just because you friended John E Resig on facebook.

xf86enodev
Mar 27, 2010

dis catte!

Ender.uNF posted:

relying on the programmer to read the doc

This is btw the main reason why JSON is the best data exchange format.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
I understand some of the complaint. Writing boilerplate code to parse JSON data structures and construct instances of the types in your language's native type system isn't too fun. A lot of it could be generated, as it's the same mechanized work over and over.

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

Suspicious Dish posted:

I understand some of the complaint. Writing boilerplate code to parse JSON data structures and construct instances of the types in your language's native type system isn't too fun. A lot of it could be generated, as it's the same mechanized work over and over.

Are you suggesting some sort of automated parsing system? Excellent idea, we could call it a "parser" and put it in the standard library of Literally Every Language.

nielsm
Jun 1, 2009



Jonnty posted:

Are you suggesting some sort of automated parsing system? Excellent idea, we could call it a "parser" and put it in the standard library of Literally Every Language.

That doesn't really solve the problem of going from a JSON file to a filled out C++ object with 15 fields, and then have 8 different classes you need to solve that for.
(Of course you could also just read things directly from the dictionaries produced by the parser, but that doesn't solve the problem of validating data, and comes at a risk of worse performance.)

ToxicFrog
Apr 26, 2008


xf86enodev posted:

This isn't directed at you but seriously it screams :effort:
But this is what's wrong with the hacking superstar coder culture these days.

Read the loving manual and don't reinvent the loving wheel.

There are probably at least a dozen "tools" on github that are supposed to overcome problems that could be solved by actually just "interacting" with your peers.

Read the docs your coworkers left you, ask them stuff you don't understand, just make the loving phone call that'll take 10 minutes out of your reddit-browsing-time.

Maybe your ego tells you otherwise but you're not above it all just because you friended John E Resig on facebook.

You know what would be even better? If we had some kind of automatic tool that could check the data for semantic well-formedness as well as simple syntactic validity. I think I've heard of programming languages that have a "static type checker" that does something similar. We could call it, I don't know, a "schema validator", that sounds like a catchy name.

And if we have something like that, maybe we can even have it generate properly typechecked code for going from JSON to data in memory and back again, rather than just shoving everything into a bunch of nested hash tables and then manually writing code to check it for well-formedness!

Then again, maybe I'm just being a scrub and real programmers do all of their work in Ruby and spit on the filthy static-typing users who want some kind of pre-runtime error checking whenever they pass in the hall.

Doctor w-rw-rw-
Jun 24, 2008

Jonnty posted:

Are you suggesting some sort of automated parsing system? Excellent idea, we could call it a "parser" and put it in the standard library of Literally Every Language.

To be fair, I work on android and it'd be super swell if, instead of using Jackson's object mapping, which relies on reflection and the tree model, if I could generate a streaming parser instead. Less memory and reflection overhead. And what about the developer who has read the docs and now has to replicate the parser work across Java (Android), Objective-C (iOS), Python (Desktop), and PHP (unfortunate choice of server)?

Not that I'd use it, but having a JSON schema wouldn't be *all* bad in all situations. All good tools are doomed to noob abuse anyways.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
Anyone use Google Protocol Buffers?

Suspicious Dish
Sep 24, 2011

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

Jonnty posted:

Are you suggesting some sort of automated parsing system?

No.

ToxicFrog
Apr 26, 2008


trex eaterofcadrs posted:

Anyone use Google Protocol Buffers?

Are you sure you meant to post this in Coding Horrors?

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

ToxicFrog posted:

Are you sure you meant to post this in Coding Horrors?

Yeah you guys are all talking about serialization, and I've never used it professionally so I was just tossing it out there to see if anyone had experience with it, in a horrible manner of course.

KaneTW
Dec 2, 2011

This thread has gone meta.

E: ^ post it in the "small programming questions" thread

Zombywuf
Mar 29, 2008

Have we just invented a JSON ORM?

Suspicious Dish
Sep 24, 2011

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

Zombywuf posted:

Have we just invented a JSON ORM?

No.

Zombywuf
Mar 29, 2008

Thank gently caress for that.

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Maybe allow base64 encoded strings as literals, saves two bytes from the quotes :v:

Seems like transporting large blobs of binary data might be useful to some people and I can think of one reason why I'd rather transport the raw binary rather than an base64 encoded string but it's a probably a pretty specific use case.

Just something I wouldn't mind if they implemented into some future version of JSON. But then it wouldn't be able to use it anyways while we wait for users to stop using older browsers/implementations.

Strong Sauce fucked around with this message at 22:47 on May 29, 2012

that awful man
Feb 18, 2007

YOSPOS, bitch

Zombywuf posted:

Have we just invented a JSON ORM?

Goon project.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."

Strong Sauce posted:

Just something I wouldn't mind if they implemented into some future version of JSON. But then it wouldn't be able to use it anyways while we wait for users to stop using older browsers/implementations.

Not to pick on you, but:

Douglas Crockford posted:

JSON has no version number. No revisions to the JSON grammar are anticipated. If something has a 1.0, it will inevitably get a 1.1 and a 2.0, and everything is crap until it is 3.0. JSON is very stable.

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Internet Janitor posted:

Not to pick on you, but:

Well like I said, I'm not exactly handling large blobs of data using JSON right now, so there's no real effect on me. I merely stated that I could see that some people would find use in having JSON support a raw binary blob. MongoDB's already taken that idea and implemented it with BSON so Crockford saying that doesn't mean it'll stop people from implementing variations on his original idea.

KaneTW
Dec 2, 2011

Strong Sauce posted:

Well like I said, I'm not exactly handling large blobs of data using JSON right now, so there's no real effect on me. I merely stated that I could see that some people would find use in having JSON support a raw binary blob. MongoDB's already taken that idea and implemented it with BSON so Crockford saying that doesn't mean it'll stop people from implementing variations on his original idea.

Well, you can always base64 it as was said previously in this thread. Anyway, if you're handling large blobs often enough that you'd need specialized support for it, JSON might not be the right choice.

Doctor w-rw-rw-
Jun 24, 2008
I can take a token stream from Jackson and write an extremely simple state machine to populate a data structure of my choosing. The moment this is not the case is the moment that JSON stops being more useful than XML, IMO.

People who think it's okay to just add some syntax to a text interchange format because it makes their lives simpler should be forced to work at lower levels and see that they're not eliminating complexity, they're just putting it elsewhere. Just base64-encode your binary blobs, if you're going to use JSON, or use a binary format.

I support JSON schema because it's validation and not an extension of the syntax itself (as I understand it), but the kind of person who adds extensions to the syntax itself of a straightforward format "because it makes it nicer" are terrible, terrible people who have ignorantly wrought destruction on productivity in the name of good.

No, I'm not at all traumatized by someone who (several years ago) claimed that XML parsers should allow spaces in tag names and went ahead and wrote a lovely, buggy XML parser to foist his "gift" on all of his underlings, why do you ask?

(second paragraph edited for clarity)

Doctor w-rw-rw- fucked around with this message at 02:25 on May 30, 2012

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Zombywuf posted:

Have we just invented a JSON ORM?

You don't really need one, since in either Mongo or CouchDB you can just put json data right into them.

Also, ^ my god...

Doctor w-rw-rw-
Jun 24, 2008

trex eaterofcadrs posted:

You don't really need one, since in either Mongo or CouchDB you can just put json data right into them.

Also, ^ my god...

Which part? Again, I probably wouldn't use a JSON schema, but it's not as abhorrent as tacking on extensions that make it harder to parse.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Doctor w-rw-rw- posted:

Which part? Again, I probably wouldn't use a JSON schema, but it's not as abhorrent as tacking on extensions that make it harder to parse.

Xml tags w/ spaces. That's "quit on the spot" kind of poo poo right there.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
I was just looking through the pictures I took of bad code at my last job, and I saw this and it made me chuckle:

C# code:
public string SetNull(string s) 
{
	if (s == null || s == "") 
	{
		return "";
	}
	else
	{
		return s;
	}
}
If you're unfamiliar with C#, the entire method could be rewritten using the null coalescing operator (??) and be one line. It was pretty indicative of general code quality.

I forget if my spirit was too crushed to bother refactoring by that point, but this would've made a lot more sense:
C# code:
public static string ToNonNullString(this string s) 
{
	return s ?? string.Empty;
}

Simulated
Sep 28, 2001
Lowtax giveth, and Lowtax taketh away.
College Slice

xf86enodev posted:

This is btw the main reason why JSON is the best data exchange format.

I have to write these APIs and just like relying on the user to make security decisions is an automatic failure, relying on the programmer to read and fully comprehend the docs is doomed from the start. I have no desire to reinvent XML (or God forbid XSD) but some basic ability to describe my API in a standardized way would be extremely helpful. Depending on my library/platform, it could even be automatic and verified by the compiler to match the code (to some degree).


Jonnty posted:

Are you suggesting some sort of automated parsing system? Excellent idea, we could call it a "parser" and put it in the standard library of Literally Every Language.

JavaScript's idea of what constitutes an object doesn't always mesh with other languages... And some platforms may or may not have JSON parsers. Everyone ends up reinventing the wheel over and over.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."

Ender.uNF posted:

some platforms may or may not have JSON parsers.

json.org lists parsers for ASP, ActionScript, Bash, BlitzMax, C, C++, C#, Clojure, Cobol, ColdFusion, D, Delphi, E, Erlang, Fantom, Go, Haskell, HaXe, Java, JavaScript, Lisp, LotusScript, Lua, Matlab, Objective-C, OCaml, OpenLaszlo, Perl, PHP, Pike, PL/SQL, PowerShell, Prolog, Puredata, Python, Qt, R, Racket, Rebol, RPG, Ruby, Scheme, Squeak, Symbian, Tcl, VisualBasic and Visual FoxPro, and most of those languages offer several implementations to pick from. It's pretty available.

Look Around You
Jan 19, 2009

Ithaqua posted:

I was just looking through the pictures I took of bad code at my last job, and I saw this and it made me chuckle:

C# code:
public string SetNull(string s) 
{
	if (s == null || s == "") 
	{
		return "";
	}
	else
	{
		return s;
	}
}
If you're unfamiliar with C#, the entire method could be rewritten using the null coalescing operator (??) and be one line. It was pretty indicative of general code quality.

I forget if my spirit was too crushed to bother refactoring by that point, but this would've made a lot more sense:
C# code:
public static string ToNonNullString(this string s) 
{
	return s ?? string.Empty;
}

I think the fact that the method is called SetNull is horrible. I would have no idea what s = SetNull(s) would mean in code. And it's not even static?

e: this would be horrible even in a language without the null coalescing operator. I'd probably just write s = (s == null) ? "" : s;. There's absolutely no need for a function there at all.

Look Around You fucked around with this message at 05:31 on May 30, 2012

Doctor w-rw-rw-
Jun 24, 2008

Internet Janitor posted:

json.org lists parsers for ASP, ActionScript, Bash, BlitzMax, C, C++, C#, Clojure, Cobol, ColdFusion, D, Delphi, E, Erlang, Fantom, Go, Haskell, HaXe, Java, JavaScript, Lisp, LotusScript, Lua, Matlab, Objective-C, OCaml, OpenLaszlo, Perl, PHP, Pike, PL/SQL, PowerShell, Prolog, Puredata, Python, Qt, R, Racket, Rebol, RPG, Ruby, Scheme, Squeak, Symbian, Tcl, VisualBasic and Visual FoxPro, and most of those languages offer several implementations to pick from. It's pretty available.

Indeed. JSON is so simple that assuming you can quote stuff properly, your choice of tokens are pretty much "{", "}", "[", "]", ",", "false", "true", "null", field names (string + a colon) , numbers, and strings (see Jackson JsonToken javadoc). Any language capable of even basic string operations should parse no problem.

...unless you decide to add a bunch of bullshit to the language specification, like functions. Gah.

EDIT:
^^^
Oh man, I wish Java had the null coalescing operator. I suppose my solution of using Optional<T> from Guava mixed with .or(defaultValue) is a close second.

Look Around You
Jan 19, 2009

Doctor w-rw-rw- posted:

Indeed. JSON is so simple that assuming you can quote stuff properly, your choice of tokens are pretty much "{", "}", "[", "]", ",", "false", "true", "null", field names (string + a colon) , numbers, and strings (see Jackson JsonToken javadoc). Any language capable of even basic string operations should parse no problem.

...unless you decide to add a bunch of bullshit to the language specification, like functions. Gah.

EDIT:
^^^
Oh man, I wish Java had the null coalescing operator. I suppose my solution of using Optional<T> from Guava mixed with .or(defaultValue) is a close second.

Optional looks pretty cool, but it's kind of funny how the comments on the API explanation act like it's a novel concept when it isn't at all.

e: Java needs first class functions. Then it may get somewhat more usable.

e2: apparently guava adds some support for functional programming too. Huh. I'd never actually heard of the library before (but then I avoid java as much as possible)

Look Around You fucked around with this message at 05:49 on May 30, 2012

Adbot
ADBOT LOVES YOU

Opinion Haver
Apr 9, 2007

Look Around You posted:

Optional looks pretty cool, but it's kind of funny how the comments on the API explanation act like it's a novel concept when it isn't at all.

e: Java needs first class functions. Then it may get somewhat more usable.

quote:

Optional is not intended as a direct analogue of any existing "option" or "maybe" construct from other programming environments, though it may bear some similarities.

Ahahaha.

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