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
brap
Aug 23, 2004

Grimey Drawer
javascript haters like to say that js doesn't even have a standard library, and inevitably the first example they think of for something they want in a standard library is JSON parsing, something which has a very simple and good implementation built-in in javascript, but everyone uses a third party library for in .net and java

Adbot
ADBOT LOVES YOU

Nomnom Cookie
Aug 30, 2009



or as a conscientious library author, make sure to bundle and rename Jackson

Shaggar
Apr 26, 2006

brap posted:

javascript haters like to say that js doesn't even have a standard library, and inevitably the first example they think of for something they want in a standard library is JSON parsing, something which has a very simple and good implementation built-in in javascript, but everyone uses a third party library for in .net and java

js is a dynamic language so inconsistent and unknown typing in json is ok. in c# you want real types so you need something capable of consistently and safely translating json

Sagacity
May 2, 2003
Hopefully my epitaph will be funnier than my custom title.

brap posted:

javascript haters like to say that js doesn't even have a standard library,
wow, next thing you'll be telling us is you can even do magical things like reading files from disk in js

Volte
Oct 4, 2004

woosh woosh

Shaggar posted:

the date sniffing in newtonsoft json only happens if you are using dynamic typing and have date sniffing on. you should not be using dynamic typing so it will never be an issue.
Did you read the GitHub issue?

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat
never use javascript

Soricidus
Oct 21, 2010
freedom-hating statist shill

brap posted:

javascript haters like to say that js doesn't even have a standard library, and inevitably the first example they think of for something they want in a standard library is JSON parsing, something which has a very simple and good implementation built-in in javascript, but everyone uses a third party library for in .net and java

this is a historical accident. json seemed better than xml to idiot webdevs because you could eval it in js, with such dire security implications that the browser makers had no choice but to agree a standard json parsing api to protect users.

meanwhile when you're writing interesting programs in a language like java or c#, you will often need more functionality than the basic javascript implementation provides. like the ability to process huge datasets as event streams, or the ability to read a number and get back the exact number that was in the data. it's hard to design a one-size-fits-all approach here so it's reasonable to leave this to libraries that are free to choose different tradeoffs or experiment with different interfaces.

instead they concentrate on putting things in their standard library that people do actually expect to be there, like string formatting.

Nomnom Cookie
Aug 30, 2009



pull parsing only matters for big boy datasets so I doubt any js devs have ever needed it

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



CRIP EATIN BREAD posted:

never use javascript

animist
Aug 28, 2018
my favorite json parser is the one that parses as little json as possible

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
hey ya'll, I havent been posting here in a bit. Here's a relatively positive EN for those interested. Semi programming related.

https://forums.somethingawful.com/showthread.php?threadid=3846735&pagenumber=1213&perpage=40#post489294687

VikingofRock
Aug 24, 2008




DONT THREAD ON ME posted:

hey ya'll, I havent been posting here in a bit. Here's a relatively positive EN for those interested. Semi programming related.

https://forums.somethingawful.com/showthread.php?threadid=3846735&pagenumber=1213&perpage=40#post489294687

Glad to hear you are doing better! Congratulations and best of luck

white sauce
Apr 29, 2012

by R. Guyovich
In java, what does this statement mean when you're creating a class?

quote:

public class Card implements Comparable <Card>

NihilCredo
Jun 6, 2011

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

white sauce posted:

In java, what does this statement mean when you're creating a class?

what part is giving you trouble? implementing an interface, having a generic interface, or the interface Comparable<T> specifically?

white sauce
Apr 29, 2012

by R. Guyovich

NihilCredo posted:

what part is giving you trouble? implementing an interface, having a generic interface, or the interface Comparable<T> specifically?

It's part of one of the classes our teacher gave us to complete for a project. I've never encountered "implements Comparable <Card>" as part of a class declaration...

What's the difference between this class declaration and a regular class declaration that would say something like

quote:


public class Card {

.....

}


I'm starting to fill in the code for the Card.java, then Deck.java, then Player.java, then Game.java....

I already have a tester class.

white sauce fucked around with this message at 21:09 on Oct 28, 2018

PokeJoe
Aug 24, 2004

hail cgatan


It implements an interface aka a required method that allows you to pass the class as an additional type i.e.

public void takeComparable(Comparable <T>) { ... }

would take in any class that implements comparable.

The <Card> means that you are using that interface for a particular type of comparable.

white sauce
Apr 29, 2012

by R. Guyovich

PokeJoe posted:

It implements an interface aka a required method that allows you to pass the class as an additional type i.e.

public void takeComparable(Comparable <T>) { ... }

would take in any class that implements comparable.

The <Card> means that you are using that interface for a particular type of comparable.

I see.

I have the skeleton to this method:

quote:

public int compareTo(Card c){
//based on rank
// use this method to compare cards so they
// may be easily sorted

}

Would this be the method you're referring to? Also, what is this called in Java, just "interface implementation"? I wanna read up on it in some place that isn't my horrible textbook.

mystes
May 31, 2006

white sauce posted:

I see.

I have the skeleton to this method:


Would this be the method you're referring to? Also, what is this called in Java, just "interface implementation"? I wanna read up on it in some place that isn't my horrible textbook.
Maybe you should try googling for java interfaces? Or ask your teacher who's getting paid to explain this stuff to you?

PokeJoe
Aug 24, 2004

hail cgatan


Yes, comparable is a common java interface that generally returns a negative value when an item is less than the one it's compared to, 0 if equal, and positive if more than. When in doubt, check the docs.

quote:

public interface Comparable<T>
This interface imposes a total ordering on the objects of each class that implements it. This ordering is referred to as the class's natural ordering, and the class's compareTo method is referred to as its natural comparison method.
Lists (and arrays) of objects that implement this interface can be sorted automatically by Collections.sort (and Arrays.sort). Objects that implement this interface can be used as keys in a sorted map or as elements in a sorted set, without the need to specify a comparator.

The natural ordering for a class C is said to be consistent with equals if and only if e1.compareTo(e2) == 0 has the same boolean value as e1.equals(e2) for every e1 and e2 of class C. Note that null is not an instance of any class, and e.compareTo(null) should throw a NullPointerException even though e.equals(null) returns false.

It is strongly recommended (though not required) that natural orderings be consistent with equals. This is so because sorted sets (and sorted maps) without explicit comparators behave "strangely" when they are used with elements (or keys) whose natural ordering is inconsistent with equals. In particular, such a sorted set (or sorted map) violates the general contract for set (or map), which is defined in terms of the equals method.

For example, if one adds two keys a and b such that (!a.equals(b) && a.compareTo(b) == 0) to a sorted set that does not use an explicit comparator, the second add operation returns false (and the size of the sorted set does not increase) because a and b are equivalent from the sorted set's perspective.

Virtually all Java core classes that implement Comparable have natural orderings that are consistent with equals. One exception is java.math.BigDecimal, whose natural ordering equates BigDecimal objects with equal values and different precisions (such as 4.0 and 4.00).

For the mathematically inclined, the relation that defines the natural ordering on a given class C is:

{(x, y) such that x.compareTo(y) <= 0}.

The quotient for this total order is:
{(x, y) such that x.compareTo(y) == 0}.

It follows immediately from the contract for compareTo that the quotient is an equivalence relation on C, and that the natural ordering is a total order on C. When we say that a class's natural ordering is consistent with equals, we mean that the quotient for the natural ordering is the equivalence relation defined by the class's equals(Object) method:
{(x, y) such that x.equals(y)}.
This interface is a member of the Java Collections Framework.


They're just called interfaces.

http://tutorials.jenkov.com/java/interfaces.html

The <T> is a generic.
https://www.tutorialspoint.com/java/java_generics.htm

white sauce
Apr 29, 2012

by R. Guyovich

mystes posted:

Maybe you should try googling for java interfaces? Or ask your teacher who's getting paid to explain this stuff to you?

Teacher is unapproachable so we are basically left to our own devices. I just needed a simple explanation from an actual human.

I’ve found that googling for poo poo I don’t understand just leads me to places like Stackoverflow.com or other weird java websites that were obviously written by people who have no grasp of English. But your comment is appreciated.

white sauce
Apr 29, 2012

by R. Guyovich

PokeJoe posted:

Yes, comparable is a common java interface that generally returns a negative value when an item is less than the one it's compared to, 0 if equal, and positive if more than. When in doubt, check the docs.



They're just called interfaces.

http://tutorials.jenkov.com/java/interfaces.html

The <T> is a generic.
https://www.tutorialspoint.com/java/java_generics.htm

Thank you so much. I’m just starting to learn to navigate the java docs and the api library.

suffix
Jul 27, 2013

Wheeee!

DONT THREAD ON ME posted:

hey ya'll, I havent been posting here in a bit. Here's a relatively positive EN for those interested. Semi programming related.

https://forums.somethingawful.com/showthread.php?threadid=3846735&pagenumber=1213&perpage=40#post489294687

best of luck op, ull always be an honorary terrible programmer here

Arcsech
Aug 5, 2008
i feel seen

Nomnom Cookie
Aug 30, 2009



Arcsech posted:

i feel seen



last panel is fun times

also flashback to arguing for months that the patch removing fsync was a bad idea and getting ignored until corruption took down a diy-AZ

CPColin
Sep 9, 2003

Big ol' smile.
For years, I implemented compareTo() in Java using subtraction and never thought about what happens when one value is very positive and the other value is very negative haha. (If the subtraction overflows, you get the opposite answer from what you wanted.) I guess it never came up, because I was usually comparing two values that were almost certainly both going to be positive.

There's a good reason why languages like Ceylon return "smaller", "equal", or "larger" from comparison operations, instead of (some negative number), zero, and (some positive number).

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

Arcsech posted:

i feel seen



lol I'm working on an eventually consistent system right now for work

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

CPColin posted:

For years, I implemented compareTo() in Java using subtraction and never thought about what happens when one value is very positive and the other value is very negative haha. (If the subtraction overflows, you get the opposite answer from what you wanted.) I guess it never came up, because I was usually comparing two values that were almost certainly both going to be positive.

There's a good reason why languages like Ceylon return "smaller", "equal", or "larger" from comparison operations, instead of (some negative number), zero, and (some positive number).

I think most of us have done this at one time or another. doing it any other way is more typing after all 😀

I've sometimes wondered if it would be better to have a distinct NumericallyComparable interface with a method that returns the numerical representation of the object so the language can implement the compareTo optimally.

then classic Comparable would be reserved only for classes that can't be compared via a single numerical value.

Corla Plankun
May 8, 2007

improve the lives of everyone
is this like a java thing because i dont understand why subtraction would ever be necessary? don't all languages have greater-than and less-than built in?

edit: i think this reads like i'm being snarky but i am genuinely asking because it seems like a weird thing for me to be confused about but i'm not understanding the discussion

Nomnom Cookie
Aug 30, 2009



saves branches, makes programmers feel like they're writing fast code

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

Corla Plankun posted:

is this like a java thing because i dont understand why subtraction would ever be necessary? don't all languages have greater-than and less-than built in?

edit: i think this reads like i'm being snarky but i am genuinely asking because it seems like a weird thing for me to be confused about but i'm not understanding the discussion

comparable is an interface for classes to implement to allow them to be compared. in Java compareTo returns an integer. less than 0 means "sorts first" 0 means they're the same, and greater than 0 means "sorts after".

when the comparison is just a numeric field on the class people usually implement it as "return thing1.num -thing2.num"

in more complex scenarios you might instead use if then chains to return +-1 or 0.

for the former it'd be nice to just have a way to flag the field that needs to be compared instead of having to implement the same thing all the time.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
just use ComparisonChain

Nomnom Cookie
Aug 30, 2009



intellij generates all my compareTos, toStrings, and hashCodes

Sapozhnik
Jan 2, 2005

Nap Ghost

Kevin Mitnick P.E. posted:

intellij generates all my compareTos, toStrings, and hashCodes

maybe autovalue should do that for you instead

gonadic io
Feb 16, 2011

>>=

Corla Plankun posted:

is this like a java thing because i dont understand why subtraction would ever be necessary? don't all languages have greater-than and less-than built in?

edit: i think this reads like i'm being snarky but i am genuinely asking because it seems like a weird thing for me to be confused about but i'm not understanding the discussion

Also java doesn't have operator overloading so < and > are on built-in numbers only

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



jit bull transpile posted:

comparable is an interface for classes to implement to allow them to be compared. in Java compareTo returns an integer. less than 0 means "sorts first" 0 means they're the same, and greater than 0 means "sorts after".

when the comparison is just a numeric field on the class people usually implement it as "return thing1.num -thing2.num"

in more complex scenarios you might instead use if then chains to return +-1 or 0.

for the former it'd be nice to just have a way to flag the field that needs to be compared instead of having to implement the same thing all the time.

why the heclk wouldnt you return self.num.compareTo(other.num)

cinci zoo sniper
Mar 15, 2013




this is going to be fun. our new chad chief system architect firstly plans to take our gigantic legacy product and migrate it over to an entirely new codebase developed for it with a downtime of under an hour (neither the legacy product nor his system design have any documentation to show), and secondly he smugly proclaimed that he will take care of document storage question and we will be given a special sql interface to work with xml documents without storing them in rdbms


sure champ, just let me know when i can reap that sick hn karma by publishing it revolution from the hairy anus of russia first

cinci zoo sniper
Mar 15, 2013




to put document store query thing into perspective, the technical requirement is that documents and relational data are both accessible within a single sql:2011+ select

cinci zoo sniper fucked around with this message at 09:53 on Oct 29, 2018

cinci zoo sniper
Mar 15, 2013




the reasoning about lack of documentation for system architecture is that if it will be done in full then 90% of time will be spent managing the docs and only the rest for development :thunk:

Powerful Two-Hander
Mar 10, 2004

Mods please change my name to "Tooter Skeleton" TIA.


horrific nested mvc view update status: it's bad bront

after banging my head on this for a week I realised that what I was trying to do was dumb and required that the entire model state be represented in the display template in order to post back properly but at the same time that made an individual element impossible to edit dynamically because the ids for binding would reference the larger model and not just the sub element being used.

so anyway, I realised that seeing as this is editing a list of Farts that all implement IButt I should stop dying on the hill of stateless pages and have the Fart Editor just add Farts to a list in the user session and return a flat display render, then on save just add a step to get all session Farts and save them instead of having to include them in the main nested List<IButt> model

so yeah, that was a waste of my life. I did learn a lot about manipulating the way binding Id refs generate in mvc though so there is that. In particular, you can extend the BeginCollectionItem helper library to take a prefix from the session so you can dynamically change the prefix of list items to create nested lists.

i mean, it's still a total pain in the rear end to do but you can do it. at one point I was 8 layers deep into nested element names lmao

Powerful Two-Hander fucked around with this message at 12:03 on Oct 29, 2018

Adbot
ADBOT LOVES YOU

gonadic io
Feb 16, 2011

>>=
app team to us: we'd like an api to get this data please
my team: sure here is a change-event avro topic on kafka you can materialise the view however you want

it is literally:

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