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
Sagacity
May 2, 2003
Hopefully my epitaph will be funnier than my custom title.

Kevin Mitnick P.E. posted:

the problems start when you need to go someplace that spring boot is not designed for

yes fair enough, if you use a framework for something that it's not designed for, it won't work as well
but that's a fairly generic argument (<T>) you can use for anything

curious to hear what kind of things you've seen people try to shoehorn into a spring boot application then :)

Adbot
ADBOT LOVES YOU

Nomnom Cookie
Aug 30, 2009



Sagacity posted:

yes fair enough, if you use a framework for something that it's not designed for, it won't work as well
but that's a fairly generic argument (<T>) you can use for anything

curious to hear what kind of things you've seen people try to shoehorn into a spring boot application then :)

yeah maybe i just don't like framework. "this codebase will never need to do anything beyond the framework's design" feels to me like a strong claim to make but then I've only had one job doing a crud app. and that time i got tasked with integrating an ecommerce framework into the spring boot poc my boss did. it didn't go well

prisoner of waffles
May 8, 2007

Ah! well a-day! what evil looks
Had I from old and young!
Instead of the cross, the fishmech
About my neck was hung.
c# doesn't have return type covariance

If
Flower has subclass Rose; and
FlowerSeller has subclass RoseSeller; and
FlowerSeller::Sell is declared to return Flower;
RoseSeller::Sell cannot be declared to return Rose

I mean I know this can be worked around somewhat using some annoying CRTP-like generic arguments but seriously
"C++ has it" is not a good argument for many specific nibs and nubs of inheritance etc. but this is a good and useful thing that C++ had a loving while ago

https://github.com/dotnet/csharplang/issues/49

e: checked and yes, java has this. C#, YOOPLPOS

ee: yes, this is (in my experience) the first language-level thing that Java has over C#

prisoner of waffles fucked around with this message at 17:00 on Oct 11, 2018

tef
May 30, 2004

-> some l-system crap ->
isn't the recursive typedef how you work around this in java

tef
May 30, 2004

-> some l-system crap ->
Enum<E extends Enum<E>>

prisoner of waffles
May 8, 2007

Ah! well a-day! what evil looks
Had I from old and young!
Instead of the cross, the fishmech
About my neck was hung.

tef posted:

isn't the recursive typedef how you work around this in java

no

not as of tyool 2004

https://blogs.oracle.com/sundararajan/covariant-return-types-in-java

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
iirc Java enums are way better than C#

raminasi
Jan 25, 2005

a last drink with no ice
i think the fact that kludging it in when you need it isn't too painful (thanks method hiding) means that it's not gonna show up for awhile, if ever.

Carthag Tuek
Oct 15, 2005

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



Janitor Prime posted:

iirc Java enums are way better than C#

swift enums own bones

Shaggar
Apr 26, 2006

Janitor Prime posted:

iirc Java enums are way better than C#

definitely

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Krankenstyle posted:

swift enums own bones

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

swenums

Bloody
Mar 3, 2013

where's that flow chart for deciding api response codes i need to respond with a "the thing you asked for with your parameters doesnt exist although this method does " but 404 feels kinda misleading and im wondering if there are more descriptive alternatives

Fiedler
Jun 29, 2002

I, for one, welcome our new mouse overlords.
it doesn't matter what the gently caress you return because no one can agree on any of it. just pick something and write good documentation.

Dylan16807
May 12, 2010
at the very least I'd say a generic 400 is better than 404

maybe 422 Unprocessable Entity? The request was well-formed but was unable to be followed due to semantic errors.

prisoner of waffles
May 8, 2007

Ah! well a-day! what evil looks
Had I from old and young!
Instead of the cross, the fishmech
About my neck was hung.
The webmachine diagram?

https://raw.githubusercontent.com/wiki/webmachine/webmachine/images/http-headers-status-v3.png

I don't think there's an error code corresponding to "this collection of objects does exist, but not the object you requested"

So just make it up

Cybernetic Vermin
Apr 18, 2005

the most treacherous code in any project is anyway code that tries to "handle" an error, so reporting a very accurate error code is just inspiring bad thinking. as likely as anything something is wrong with the process state, and the best bet is to crash pretty hard and spin all state up fresh (i.e. the erlang insight)

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Bloody posted:

where's that flow chart for deciding api response codes i need to respond with a "the thing you asked for with your parameters doesnt exist although this method does " but 404 feels kinda misleading and im wondering if there are more descriptive alternatives

I like the flow charts on this page http://www.codetinkerer.com/2015/12/04/choosing-an-http-status-code.html

Nomnom Cookie
Aug 30, 2009



Cybernetic Vermin posted:

the most treacherous code in any project is anyway code that tries to "handle" an error, so reporting a very accurate error code is just inspiring bad thinking. as likely as anything something is wrong with the process state, and the best bet is to crash pretty hard and spin all state up fresh (i.e. the erlang insight)

iow all that matters is the first digit of the status code

MrMoo
Sep 14, 2000

Bloody posted:

where's that flow chart for deciding api response codes i need to respond with a "the thing you asked for with your parameters doesnt exist although this method does " but 404 feels kinda misleading and im wondering if there are more descriptive alternatives

That would be rather dangerous for many obvious reasons, but you can always provide a body with a 404 that provides the information.

A basic spellchecking router could just response with a 301 or 308 though.

redleader
Aug 18, 2005

Engage according to operational parameters

Fiedler posted:

it doesn't matter what the gently caress you return because no one can agree on any of it. just pick something and write good documentation.

prisoner of waffles
May 8, 2007

Ah! well a-day! what evil looks
Had I from old and young!
Instead of the cross, the fishmech
About my neck was hung.

Bookmarked, thanks

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

Bloody posted:

where's that flow chart for deciding api response codes i need to respond with a "the thing you asked for with your parameters doesnt exist although this method does " but 404 feels kinda misleading and im wondering if there are more descriptive alternatives

return 200 and a zipped PDF containing a bitmap rendering of the backtrace for the error

be sure to use CCITT Group IV Fax encoding, make the image like 1200 DPI with one bit per CMYK channel, put the image origin at bottom right, and break the image into tiles

eschaton fucked around with this message at 05:26 on Oct 12, 2018

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
respond with "GET ~/Documents/mom/shower7.png", maybe the client will get confused and it'll work

Carthag Tuek
Oct 15, 2005

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



rjmccall posted:

respond with "GET ~/Documents/mom/shower7.png", maybe the client will get confused and it'll work

:yeshaha:

Captain Foo
May 11, 2004

we vibin'
we slidin'
we breathin'
we dyin'

rjmccall posted:

respond with "GET ~/Documents/microwavemom/shower7.png", maybe the client will get confused and it'll work

Stringent
Dec 22, 2004


image text goes here

Krankenstyle posted:

swift enums own bones

Sweeper
Nov 29, 2007
The Joe Buck of Posting
Dinosaur Gum
rust enums, also good. I'm a big fan of the error handling in rust and being able to return enums which have differing content is super useful

havelock
Jan 20, 2004

IGNORE ME
Soiled Meat

prisoner of waffles posted:

c# doesn't have return type covariance

If
Flower has subclass Rose; and
FlowerSeller has subclass RoseSeller; and
FlowerSeller::Sell is declared to return Flower;
RoseSeller::Sell cannot be declared to return Rose

I mean I know this can be worked around somewhat using some annoying CRTP-like generic arguments but seriously
"C++ has it" is not a good argument for many specific nibs and nubs of inheritance etc. but this is a good and useful thing that C++ had a loving while ago

https://github.com/dotnet/csharplang/issues/49

e: checked and yes, java has this. C#, YOOPLPOS

ee: yes, this is (in my experience) the first language-level thing that Java has over C#


Seller<T> where T : Flower
T Sell

Done. Right?

If you really have to, RoseSeller : Seller<Rose>

I bet Java has it because of type erasure.

havelock fucked around with this message at 23:58 on Oct 17, 2018

Nomnom Cookie
Aug 30, 2009



java generates two methods

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer
I really hate that in Java you can't overload functions in this way:

Java code:
public void listFunc(List<Foo>);
public void listFunc(List<Bar>);
I know why it's that way but there's been a handful of times I really wished I could do it. instead you just kinda gotta put the lists content type into the function name.

Nomnom Cookie
Aug 30, 2009



Kevin Mitnick P.E. posted:

java generates two methods

type erasure is part of generics and return type covariance doesn't involve type variables to what could get erased

code:
class A {
    A getThis() {
        return this;
    }
}

class B extends A {
    B getThis() {
        return this;
    }
}
If you have an A reference then A tmp = a.getThis(); will generate a call to A.getThis()LA;. The JVM doesn't know about return type convariance so B has to have an override. At the call site it's just a regular virtual call.

If you have a B reference then you can do B tmp = b.getThis(); which will generate a call to B.getThis()LB;. Thus B needs a second method. You can imagine this continuing with a class C extends B that overrides again and ends up with two synthetic methods, and so on.

This all works because while Java doesn't allow overloading on return type, the JVM does. Method calls in JVM bytecode include the return type as part of the reference so it's never ambiguous.

prisoner of waffles
May 8, 2007

Ah! well a-day! what evil looks
Had I from old and young!
Instead of the cross, the fishmech
About my neck was hung.

havelock posted:

Seller<T> where T : Flower
T Sell

Done. Right?

If you really have to, RoseSeller : Seller<Rose>

yes. almost. as you wrote it, Seller<Rose> is not a subclass of Seller<Flower>. To fix that we gotta use a covariant type parameter.
code:
interface Seller<out T> where T : Flower { T Sell(); }
so the easy way
code:
interface Flower{}
interface Rose : Flower{}
interface FlowerSeller : { Flower Sell(); }
interface RoseSeller : FlowerSeller { Rose Sell(); }
vs. the hard way
code:
interface Flower{}
interface Rose : Flower{}
interface FlowerSeller<out T> where T : Flower { T Sell(); }
using RoseSeller = FlowerSeller<Rose>;
cool, now I'm using generics with declared variance to support something that both java and c++ make easy as hell. i'm sure that this will neither confuse dumb coworkers nor invite lots of "helpful" "suggestions" from smart coworkers during code review time

I take no pleasure in this as I would love to just be able to say, "C# is uniformly better than java"


thank's for you're service

prisoner of waffles
May 8, 2007

Ah! well a-day! what evil looks
Had I from old and young!
Instead of the cross, the fishmech
About my neck was hung.

jit bull transpile posted:

I really hate that in Java you can't overload functions in this way:

Java code:
public void listFunc(List<Foo>);
public void listFunc(List<Bar>);
I know why it's that way but there's been a handful of times I really wished I could do it. instead you just kinda gotta put the lists content type into the function name.

hmm, is there anything wrong with

Java code:
public void listFunc<T>(List<T>);
with an appropriate set of type bounds on T? (though I'll admit I find expressing type bounds in Java to be a "I'm googling it or finding my bookmark every time" kind of thing for me)

mystes
May 31, 2006

prisoner of waffles posted:

hmm, is there anything wrong with

Java code:
public void listFunc<T>(List<T>);
with an appropriate set of type bounds on T? (though I'll admit I find expressing type bounds in Java to be a "I'm googling it or finding my bookmark every time" kind of thing for me)
If java let you define your own interfaces and then write implementations for existing classes this would probably work in most cases but it doesn't, right?

E.g would a method that either takes a list of strings or a list of urls be possible in java?

Nomnom Cookie
Aug 30, 2009



No because of type erasure. void doTheThing(List<String>) and void doTheThing(List<URL>) both erase to void doTheThing(List). You will get an error at compile time if you put each method on an interface and try to implement both interfaces on a single class.

havelock
Jan 20, 2004

IGNORE ME
Soiled Meat

prisoner of waffles posted:


cool, now I'm using generics with declared variance to support something that both java and c++ make easy as hell. i'm sure that this will neither confuse dumb coworkers nor invite lots of "helpful" "suggestions" from smart coworkers during code review time

I take no pleasure in this as I would love to just be able to say, "C# is uniformly better than java"

thank's for you're service

What scenarios would you find this useful in? For consumers of your classes, they are already likely only hanging on to references to your base class, so the fact that the return type is more specialized doesn't help them. The only scenario I can think of is when you're implementing a new derived class, because in that case you aren't dealing with polymorphism, i.e., you're a RoseSeller so you know you sell Roses, vs. everyone else just dealing with Sellers and Flowers.

Are there other things I'm missing? I'm sure I've run across one or two over the years but it was never enough to make me feel like the language had a huge omission. As long as you stick to claiming "uniformly better" instead of "strictly more expressive" then I think you're fine.

Soricidus
Oct 21, 2010
freedom-hating statist shill

havelock posted:

What scenarios would you find this useful in? For consumers of your classes, they are already likely only hanging on to references to your base class, so the fact that the return type is more specialized doesn't help them. The only scenario I can think of is when you're implementing a new derived class, because in that case you aren't dealing with polymorphism, i.e., you're a RoseSeller so you know you sell Roses, vs. everyone else just dealing with Sellers and Flowers.

Are there other things I'm missing? I'm sure I've run across one or two over the years but it was never enough to make me feel like the language had a huge omission. As long as you stick to claiming "uniformly better" instead of "strictly more expressive" then I think you're fine.

in a java context it lets you have things like

code:
var foo = new StringBuilder().append(bar);
where foo ends up being of type StringBuilder, not Appendable

sure, you can just not chain methods or w/e, but it’s nice to have the option

aardvaard
Mar 4, 2013

you belong in the bog of eternal stench

prisoner of waffles posted:

yes. almost. as you wrote it, Seller<Rose> is not a subclass of Seller<Flower>. To fix that we gotta use a covariant type parameter.
code:
interface Seller<out T> where T : Flower { T Sell(); }
so the easy way
code:
interface Flower{}
interface Rose : Flower{}
interface FlowerSeller : { Flower Sell(); }
interface RoseSeller : FlowerSeller { Rose Sell(); }
vs. the hard way
code:
interface Flower{}
interface Rose : Flower{}
interface FlowerSeller<out T> where T : Flower { T Sell(); }
using RoseSeller = FlowerSeller<Rose>;
cool, now I'm using generics with declared variance to support something that both java and c++ make easy as hell. i'm sure that this will neither confuse dumb coworkers nor invite lots of "helpful" "suggestions" from smart coworkers during code review time

I take no pleasure in this as I would love to just be able to say, "C# is uniformly better than java"


thank's for you're service

that really isn't the hard way. if you have coworkers who argue with you over the fact that your generic has an "out" keyword in it then you're not going to get things done the easy way anyways.

Adbot
ADBOT LOVES YOU

luchadornado
Oct 7, 2004

A boombox is not a toy!

https://github.com/withoutboats/shifgrethor

aw yeah

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