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
Look Around You
Jan 19, 2009


Wow I suck at reading :(.

Adbot
ADBOT LOVES YOU

Opinion Haver
Apr 9, 2007

Look Around You posted:

Wow I suck at reading :(.

My point was "Guys this totally isn't OCaml's Option or Haskell's Maybe!!!" even though it's the exact same concept (except worse because you can't just write x >>= f or whatever you'd write in OCaml, you have to do some ungodly anonymous inner class hack).

Java code:
final Optional<D> result = one().flatTransform(new Function<A, Optional<D>>() {
  public Optional<D> apply(final A a) {
    return two(a).flatTransform(new Function<B, Optional<D>>() {
      public Optional<D> apply(final B b) {
        return three(b).flatTransform(new Function<C, Optional<D>>() {
          public Optional<D> apply(final C c) {
            return four(b, c);
        })
    })
})

Opinion Haver fucked around with this message at 05:54 on May 30, 2012

ultramiraculous
Nov 12, 2003

"No..."
Grimey Drawer

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.

On top of that, there definitely has been growth in high-performance JSON serializing/deserializing in the last year. For example there's UltraJson for Python and JSONKit for Objective-C, which have order-of-magnitude differences in parse times in some cases. This is probably a good time to note that it's a lot easier to incentivize this sort of high-performance work when the spec isn't changing all the goddamn time.

xf86enodev
Mar 27, 2010

dis catte!

Ender.uNF posted:

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).

There is a standardised way to describe an API, it's called English. Sure there's a margin of error depending on how well your dudes write and read but this margin grows smaller the better they cooperate with each other.
On the other hand making people try and comprehend specs goes a long way towards catching design errors early on. Relying too much on tools to autogenerate and verify your stuff only leads to a false sense of security of "Welp, it compiles. Time to move on"

The big selling point of XML was that it's machine-readable and platform-agnostic. In my opinion this is all moot as long as we still have people writing code. And that code is bound by esoteric implementation details. So the easier it is for humans to grasp the structure and layout of data the better.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
If you want a machine-checked autogenerated-tooling interchange format, there's literally nothing wrong with using XML for that!

Moving to a new technology just because it's new, even if it doesn't quite fit what you're trying to do with it, is a pretty big horror.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Look Around You posted:

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.

Yup. I also like the redundant check if (s == "") return "";. That entire first if could be replaced by if (string.IsNullOrEmpty(s)) { }

It has a lot of layers of "wtf".

Captain Capacitor
Jan 21, 2008

The code you say?

ultramiraculous posted:

On top of that, there definitely has been growth in high-performance JSON serializing/deserializing in the last year. For example there's UltraJson for Python and JSONKit for Objective-C, which have order-of-magnitude differences in parse times in some cases. This is probably a good time to note that it's a lot easier to incentivize this sort of high-performance work when the spec isn't changing all the goddamn time.

If there's one thing I wish I could change about JSON is ability to have trailing commas. I'm too used to Python dictionaries and it fucks me over every time.

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer

Ithaqua posted:

Yup. I also like the redundant check if (s == "") return "";. That entire first if could be replaced by if (string.IsNullOrEmpty(s)) { }

It has a lot of layers of "wtf".
Ugh, I recently found a similarly stupid branching statement in a codebase I was working on. Doubly nested ifs that could've just been a single ternary but it was just complicated enough that it took five seconds or so to understand. I held my nose and changed one of the parts of one of the conditions because I didn't want my name covering the whole (not unit test covered) function in a blame.

Doh004
Apr 22, 2007

Mmmmm Donuts...
Found this today while trying to determine a specific sector in some other team's solution:

code:
            if ((int.Parse(DataContext.Params["pageCode"]) == 1037) || (int.Parse(DataContext.Params["pageCode"]) == 1000 || int.Parse(DataContext.Params["pageCode"]) == 1042 || int.Parse(DataContext.Params["pageCode"]) == 1048 || int.Parse(DataContext.Params["pageCode"]) == 1036) || int.Parse(DataContext.Params["pageCode"]) == 1060 || int.Parse(DataContext.Params["pageCode"]) == 1027 || int.Parse(DataContext.Params["pageCode"]) == 1040 || int.Parse(DataContext.Params["pageCode"]) == 1028 || int.Parse(DataContext.Params["pageCode"]) == 1029 || int.Parse(DataContext.Params["pageCode"]) == 1030 || int.Parse(DataContext.Params["pageCode"]) == 1031 || int.Parse(DataContext.Params["pageCode"]) == 1032 || int.Parse(DataContext.Params["pageCode"]) == 1033 || int.Parse(DataContext.Params["pageCode"]) == 1034 || int.Parse(DataContext.Params["pageCode"]) == 1035 || int.Parse(DataContext.Params["pageCode"]) == 1059 || int.Parse(DataContext.Params["pageCode"]) == 1038 || int.Parse(DataContext.Params["pageCode"]) == 1039 || int.Parse(DataContext.Params["pageCode"]) == 1041 || int.Parse(DataContext.Params["pageCode"]) == 1046 || int.Parse(DataContext.Params["pageCode"]) == 1047 || int.Parse(DataContext.Params["pageCode"]) == 1043 || int.Parse(DataContext.Params["pageCode"]) == 1044 || int.Parse(DataContext.Params["pageCode"]) == 1045)
                return true;
            else
                return false;
Yes that's all one line, and yes this is repeated in multiple locations :saddowns:

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

xf86enodev posted:

There is a standardised way to describe an API, it's called English. Sure there's a margin of error depending on how well your dudes write and read but this margin grows smaller the better they cooperate with each other.
On the other hand making people try and comprehend specs goes a long way towards catching design errors early on. Relying too much on tools to autogenerate and verify your stuff only leads to a false sense of security of "Welp, it compiles. Time to move on"

The big selling point of XML was that it's machine-readable and platform-agnostic. In my opinion this is all moot as long as we still have people writing code. And that code is bound by esoteric implementation details. So the easier it is for humans to grasp the structure and layout of data the better.

So how's that hint/intellisense working out for you when you are four layers deep into a complex JSON structure and can't remember the field name? Or the value is a choice between 6 possibilities? Just look it up on the web right? So why bother having intellisense at all?

Most people who miss my point never have to work with data structures more complex than a twitter post, picture upload, or blog entry so they imagine the world to be just that simple. I'm not saying you are guilty of that though, it's just a general observation.

JSON is worth using because browswers have parsers for it and because using REST it traverses proxies, firewalls, etc. It has other benefits but those are significant when you want to be as broad as possible in your support. The same API can service some web widget and an integration partner. You don't have a mile-long config file (ugh WCF you rear end in a top hat). I merely wished for an agreed-upon standard way to describe a REST API over HTTP and JSON data structures using JSON itself. I don't feel like that adds much complexity/overhead and you are certainly free to ignore it if you don't have a use for it.


One example of what I am invisioning is a tool that can scan the JSON structure and automatically create an appropriate CoreData backing store and Objective-C classes and insert the boilerplate RESTKit code for you, including stuff like enum values. That doesn't free you from writing the docs or having to understand the API, but it does give you caching, offine editing, querying, and a bunch of other stuff without having to manually create the entities and keep them in sync with the JSON, or manually creating the RESTKit mapping.

Captain Capacitor
Jan 21, 2008

The code you say?

Ender.uNF posted:

One example of what I am invisioning is a tool that can scan the JSON structure and automatically create an appropriate CoreData backing store and Objective-C classes and insert the boilerplate RESTKit code for you, including stuff like enum values. That doesn't free you from writing the docs or having to understand the API, but it does give you caching, offine editing, querying, and a bunch of other stuff without having to manually create the entities and keep them in sync with the JSON, or manually creating the RESTKit mapping.

Not quite Objective-C, but I've used this before with good results.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
PHP code:
ini_set("memory_limit", "2048M");               # Increase ram limit for us
You sons of bitches.

Doctor w-rw-rw-
Jun 24, 2008

Captain Capacitor posted:

Not quite Objective-C, but I've used this before with good results.

I prefer Jackson, myself, but that's probably beside the point since RestKit does more than just JSON<->Object mapping.

xarph
Jun 18, 2001


I don't know if I should be more terrified at this response from mint:



Or my bank issuing captchas that are all four letter dictionary words, use the same color palette, and look like this:



Edit:

Wagers on when this gets deleted?

http://satisfaction.mint.com/mint/topics/mints_password_storage_cannot_handle_certain_characters_this_is_a_sign_of_a_security_vulnerability

xarph fucked around with this message at 18:57 on May 30, 2012

Zombywuf
Mar 29, 2008



I like their issue report comment system.

chglcu
May 17, 2007

I'm so bored with the USA.

Ithaqua posted:

That entire first if could be replaced by if (string.IsNullOrEmpty(s)) { }

It has a lot of layers of "wtf".

String.IsNullOrEmpty hasn't always been around, so that bit's not as much of a wtf.

Look Around You
Jan 19, 2009

prolecat posted:

String.IsNullOrEmpty hasn't always been around, so that bit's not as much of a wtf.

Checking for "" isn't really necessary though, since it's already a string. All he really had to do is check for null and return "" if it was null. It really shouldn't be a function at all; s = s ?? ""; is better if you have a null coalescing operator, or s = (s != null) ? s : ""; if you don't.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

prolecat posted:

String.IsNullOrEmpty hasn't always been around, so that bit's not as much of a wtf.

It's been around since .NET 2.0 in 2005, and the application I found the code in was considerably newer than that. IsNullOrWhitespace is new to .NET 4, so I'll give you that.

chglcu
May 17, 2007

I'm so bored with the USA.

Look Around You posted:

Checking for "" isn't really necessary though, since it's already a string. All he really had to do is check for null and return "" if it was null. It really shouldn't be a function at all; s = s ?? ""; is better if you have a null coalescing operator, or s = (s != null) ? s : ""; if you don't.

Yeah, I wasn't defending that bit.

the talent deficit
Dec 20, 2003

self-deprecation is a very british trait, and problems can arise when the british attempt to do so with a foreign culture






This isn't necessarily as bad as you think. They could have recently disallowed certain characters and might just be lazily forcing password changes when you login if your pass contains those characters. If they sent you this without you logging in though, that's terrible.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

the talent deficit posted:

This isn't necessarily as bad as you think. They could have recently disallowed certain characters and might just be lazily forcing password changes when you login if your pass contains those characters. If they sent you this without you logging in though, that's terrible.

If there is an actual reason to disallow certain characters in passwords then yes they are absolutely doing something wrong.

xf86enodev
Mar 27, 2010

dis catte!

Ender.uNF posted:

So why bother having intellisense at all?

That's a good one. I don't use intellisense et al. Sure, I use auto-completion to speed up my typing but there just isn't a tool that can take away my responsibility to "get the big picture". Sometimes I take notes on a piece of paper if things get too complicated or on days when there are too many distractions.

But when data structures or pieces of business logic get to big to be handled by a human being that's a design error.

xf86enodev fucked around with this message at 01:26 on May 31, 2012

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

xf86enodev posted:

That's a good one. I don't use intellisense et al. Sure, I use auto-completion to speed up my typing but there just isn't a tool that can take away my responsibility to "get the big picture". Sometimes I take notes on a piece of paper if things get too complicated or on days when there are too many distractions.

But when data structures or pieces of business logic get to big to be handled by a human being that's a design error.

So you are reframing your avoidance of productivity enhancements as somehow my failure to understand the big picture?

What does understanding the big picture have to do with using tools (or even code) to generate code? Are you pre-supposing that if I use a tool to auto-generate classes from specs I can't possibly understand how the underlying mechansim and protocols work? You also seem to be mixing up "big picture" with "menial copy-paste from the API spec".

Who said the problems you are capable of imagining fully represent the desirable design spaces? Just because you haven't worked with complicated systems doesn't mean they don't exist or even that they are inelegantly designed.

I am trying to be careful of accusing you of being an rear end here but it really seems like you are being one of those :smug: web 2.0 asses that think anything more complex than a twitter post is too complicated. News flash: you try designing an interface for accurately transmitting medical records and tell me you memorized all the categories, status codes, routing codes, etc. Or a students school records. Or an 850 order for telephone service. Or a multi-hundred-GB multidimensional data set with dynamically calculated recursive properties on a distributed real-time system that versions, branches, and merges data (not code!). I've worked on all of these... Some were less elegant than others but all were extremely complex real-world systems that no one person can ever know everything about which is precisely why I loving focus on the big picture and let the compiler/tools do the menial poo poo for me (unless there is a low-level problem in which case I disassemble the libraries, grab packets with wireshark, or do whatever else is needed to solve the problem because using high-level tools doesn't mean I don't understand how the whole system works).

xf86enodev
Mar 27, 2010

dis catte!
Sorry dude, I said in my first post that it wasn't directed at you personally. And I certainly didn't mean to imply you don't know how to build software.
Sure I used your last reply to sound all :smug: but seriously I was just trying to argue a general topic. (Well it was more ranting than anything else but eh)

e:

Ender.uNF posted:

Just because you haven't worked with complicated systems doesn't mean they don't exist or even that they are inelegantly designed.
Did your intellisense propose this conclusion?



Anyway this doesn't seem to be about XML vs JSON anymore so if you want to keep the discussion going feel free to PM me.

epswing
Nov 4, 2003

Soiled Meat

xf86enodev posted:

I don't use intellisense
...
I use auto-completion

Wait, these aren't the same thing? Am I missing something big here?

Look Around You
Jan 19, 2009

epswing posted:

Wait, these aren't the same thing? Am I missing something big here?

I would usually consider intellisense as something that's context sensitive, while autocomplete is just dumb word-completion that's not context aware at all.

Doctor w-rw-rw-
Jun 24, 2008

Look Around You posted:

I would usually consider intellisense as something that's context sensitive, while autocomplete is just dumb word-completion that's not context aware at all.

:| IntelliSense is Microsoft's branded autocomplete. Eclipse calls it content assist, but autocomplete is pretty much the accepted term. Now let's stop :spergin: and post about horrors, instead of turning this thread into one.

Beef
Jul 26, 2004
Calling IntelliSense and its ilk a high-level tool is the real horror here.


For future reference, it might be interesting to use 'simple/complex' and 'easy/hard' as was defined by Rich Hickey: http://www.infoq.com/presentations/Simple-Made-Easy
e.g. Forth is simple, but hard; Ruby on Rails is complex, but easy.

redleader
Aug 18, 2005

Engage according to operational parameters

Doh004 posted:

Found this today while trying to determine a specific sector in some other team's solution:

code:
            if ((int.Parse(DataContext.Params["pageCode"]) == 1037) || (int.Parse(DataContext.Params["pageCode"]) == 1000 || [snip])
                return true;
            else
                return false;
Yes that's all one line, and yes this is repeated in multiple locations :saddowns:

I scrolled along this with a rapidly-expanding grin on my face.

Munkeymon
Aug 14, 2003

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



xarph posted:

I don't know if I should be more terrified at this response from mint:



Or my bank issuing captchas that are all four letter dictionary words, use the same color palette, and look like this:



Edit:

Wagers on when this gets deleted?

http://satisfaction.mint.com/mint/topics/mints_password_storage_cannot_handle_certain_characters_this_is_a_sign_of_a_security_vulnerability


Couldn't the problem be on your bank's end? It could be that the data service they expose to Mint chokes on pipe characters, but the actual web site works fine. Am I misreading your post?

Doh004
Apr 22, 2007

Mmmmm Donuts...

redleader posted:

I scrolled along this with a rapidly-expanding grin on my face.

I'm not the greatest programmer in the world, but goddamn does this make my code look incredible... :unsmith:

epswing
Nov 4, 2003

Soiled Meat

Munkeymon posted:

Couldn't the problem be on your bank's end? It could be that the data service they expose to Mint chokes on pipe characters, but the actual web site works fine. Am I misreading your post?

Why would the bank need your plaintext mint.com password, ever?

etcetera08
Sep 11, 2008

epswing posted:

Why would the bank need your plaintext mint.com password, ever?

They don't; I'm reading it as the problem being that the password with the bank service has a character that mint's software can't handle. Mint's solution, as seen in that support email, is to change the user's password on the bank's end so it will work with Mint.

Which is stupid too, but a different stupid.

epswing
Nov 4, 2003

Soiled Meat

etcetera08 posted:

Mint's solution, as seen in that support email, is to change the user's password on the bank's end so it will work with Mint.

:aaa: it can't be that

............

:negative:

Munkeymon
Aug 14, 2003

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



I'm assuming the bank's data service (you didn't think Mint logged into their web site and scraped it did you?) can't handle the character and, since Mint can't force the bank to fix their poo poo, they basically say "If you want this to work today, you'll have to change your password so we can [also] log in [using the service your bank gives us to work with]"

LOOK I AM A TURTLE
May 22, 2003

"I'm actually a tortoise."
Grimey Drawer

Doh004 posted:

Found this today while trying to determine a specific sector in some other team's solution:

code:
code with long lovely line
Yes that's all one line, and yes this is repeated in multiple locations :saddowns:

I blame stuff like this partly on the relative difficulty of doing little ad-hoc checks for membership in some constant list in C#. In Python, even your average terrible programmer can figure out how to do this:
Python code:
int(DataContext.Params["pageCode"]) in [1000, 1037, etc.]
What's the best way to write that same line in C#? Like this?
C# code:
new int[] { 1000, 1037, etc. }.Contains(int.Parse(DataContext.Params["pageCode"]))
Not to say the Python example is good either, since obviously there should at the very least be a "ValidPageCodes" list and a function call to wrap the check, but at least it would be easy to tell what the actual codes are at a glance.

epswing
Nov 4, 2003

Soiled Meat
Correct me if I'm wrong but the codes should be in a hash-based container like a Set or a Dictionary, making the 'contains' lookup O(1) instead of O(n).

Then again, even in the horror example there are only 25 items in the list (I counted :v:), so it's not much of an optimization.

ijustam
Jun 20, 2005

This code

:negative:

All the SQL statements are just plain-text strings, with the escaping just changing single quotes into double single quotes (' -> ''). On top of that, all of the SQL statements are written into one string, which is declared at the global scope so every single method shares the same string.

But why change it if it works? :suicide:

LOOK I AM A TURTLE
May 22, 2003

"I'm actually a tortoise."
Grimey Drawer

epswing posted:

Correct me if I'm wrong but the codes should be in a hash-based container like a Set or a Dictionary, making the 'contains' lookup O(1) instead of O(n).

Then again, even in the horror example there are only 25 items in the list (I counted :v:), so it's not much of an optimization.

You're not wrong, although I'm sure you'd only feel the difference if you were executing the function many, many times per second.

Adbot
ADBOT LOVES YOU

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

epswing posted:

Correct me if I'm wrong but the codes should be in a hash-based container like a Set or a Dictionary, making the 'contains' lookup O(1) instead of O(n).

Then again, even in the horror example there are only 25 items in the list (I counted :v:), so it's not much of an optimization.

You'd have to see how efficient the hashing algorithm is compared to an average sequential scan of the array. A scan of an int array is actually pretty god drat fast.

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