New around here? Register your SA Forums Account here!

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
Qtotonibudinibudet
Nov 7, 2011



Omich poluyobok, skazhi ty narkoman? ya prosto tozhe gde to tam zhivu, mogli by vmeste uyobyvat' narkotiki

pseudorandom posted:

Maybe I'm dumb and stupid, but I loving hate CORS so much. As far as I can tell, it is only good for awful legacy apps that accepted requests like `GET /delete-everything`. But, GOD FORBID anyone like me wants to implement a `DELETE` route or use a non-standard header, because now I need to manually whitelist poo poo and endure a preflight `OPTIONS` request before anything can happen. :argh:

Browsers should have just let the lovely enterprise web apps implode.

cors does protect against some very real issues but the design and usability could maybe use some work

in my case tho cors was "protecting" requests for fonts, which apparently only require cors headers because some font authors were real upset about the possibility of people stealing their copyrighted works and were apparently oblivious to the idea of requests that don't enforce cors and/or rehosting font files elsewhere.

Adbot
ADBOT LOVES YOU

Carthag Tuek
Oct 15, 2005

altid pamo når du går
veje du burd' kende
overleved' barneår
lig' til livets ende

HoboMan posted:

nginx:
i imagine it's supposed to be said like n-gin-x (engine x) but i can't help but read it as n-ginx (en jinx)

its a hard g hth

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?

HoboMan posted:

nginx:
i imagine it's supposed to be said like n-gin-x (engine x) but i can't help but read it as n-ginx (en jinx)

for the longest time I read it as en-genics, like eugenics but with “en” instead of “eu”

which I mean it’s a predominantly Linux thing, of course it would have a name like that

Chalks
Sep 30, 2009

florida lan posted:

cors does protect against some very real issues but the design and usability could maybe use some work

in my case tho cors was "protecting" requests for fonts, which apparently only require cors headers because some font authors were real upset about the possibility of people stealing their copyrighted works and were apparently oblivious to the idea of requests that don't enforce cors and/or rehosting font files elsewhere.

I don't understand why they didn't change cors to be part of the actual request in http2 or whatever. A separate request to ask if you're allowed a resource seems so dumb

pseudorandom
Jun 16, 2010



Yam Slacker

HoboMan posted:

nginx:
i imagine it's supposed to be said like n-gin-x (engine x) but i can't help but read it as n-ginx (en jinx)

I'm pretty sure it's the "engine x" version, but drat you've got a good case for "once you see it you can't unsee it".

VikingofRock
Aug 24, 2008




Java question: I have a few large-ish functions, each of which I would like to call with two (possibly later more) different possible input types. The implementation of these functions would be largely the same when called with either input type, but there's just a small method or two in each function that would be different for each type. I know I could implement this roughly like this:

Java code:

void <T extends Baz> doOneThing(T input) {
  // lots of code...
  if (input instanceof Foo) {
    ((Foo)input).doSomething();
  } else if (input instanceof Bar) {
    ((Bar)input).doSomethingElse();
  }
  // lots more code
}

void <T extends Baz> doAnotherThing(T input) {
  // similar strategy here...
}

However, this feels pretty inelegant. For one thing, it doesn't scale well to more functions / more types. For another thing, it doesn't behave nicely if I pass it the wrong types: at best I can just make it fail at runtime. So what's the best strategy here?

A little more info: while Foo and Bar both extend Baz, Baz as a whole is very broad and most of it's subclasses won't work with these methods. I do not directly control Foo and Bar, so I can't e.g. make them both implement an interface which does what I want.

Carthag Tuek
Oct 15, 2005

altid pamo når du går
veje du burd' kende
overleved' barneår
lig' til livets ende

pseudorandom posted:

I'm pretty sure it's the "engine x" version, but drat you've got a good case for "once you see it you can't unsee it".

joking aside, its actually pronounced like the vietnamese name nguyen

Carthag Tuek
Oct 15, 2005

altid pamo når du går
veje du burd' kende
overleved' barneår
lig' til livets ende

VikingofRock posted:

Java question: I have a few large-ish functions, each of which I would like to call with two (possibly later more) different possible input types. The implementation of these functions would be largely the same when called with either input type, but there's just a small method or two in each function that would be different for each type.

pass in the different methods as parameters

pseudorandom
Jun 16, 2010



Yam Slacker

VikingofRock posted:

Java question: I have a few large-ish functions, each of which I would like to call with two (possibly later more) different possible input types. The implementation of these functions would be largely the same when called with either input type, but there's just a small method or two in each function that would be different for each type. I know I could implement this roughly like this:

Java code:
void <T extends Baz> doOneThing(T input) {
  // lots of code...
  if (input instanceof Foo) {
    ((Foo)input).doSomething();
  } else if (input instanceof Bar) {
    ((Bar)input).doSomethingElse();
  }
  // lots more code
}

void <T extends Baz> doAnotherThing(T input) {
  // similar strategy here...
}
However, this feels pretty inelegant. For one thing, it doesn't scale well to more functions / more types. For another thing, it doesn't behave nicely if I pass it the wrong types: at best I can just make it fail at runtime. So what's the best strategy here?

A little more info: while Foo and Bar both extend Baz, Baz as a whole is very broad and most of it's subclasses won't work with these methods. I do not directly control Foo and Bar, so I can't e.g. make them both implement an interface which does what I want.

Does Java have Traits yet? Alternatively, I think C# had a way to define methods where `void exampleMethod(Foo someObj)` could be called like `myFoo.exampleMethod()`; though it's been a while since I've used it. Does Java have anything similar now where you could define methods for each class that don't require you to control their full implementation?

If not, it might be hacky, but maybe make a wrapper class, or classes, that you pair with an interface.

redleader
Aug 18, 2005

Engage according to operational parameters

HoboMan posted:

also in case anyone cares (i know you don't) the very helpful "cannot GET /" error i was getting was from angular silently failing to compile

lmao

Soricidus
Oct 20, 2010
freedom-hating statist shill

VikingofRock posted:

Java question: I have a few large-ish functions, each of which I would like to call with two (possibly later more) different possible input types. The implementation of these functions would be largely the same when called with either input type, but there's just a small method or two in each function that would be different for each type. I know I could implement this roughly like this:

Java code:
void <T extends Baz> doOneThing(T input) {
  // lots of code...
  if (input instanceof Foo) {
    ((Foo)input).doSomething();
  } else if (input instanceof Bar) {
    ((Bar)input).doSomethingElse();
  }
  // lots more code
}

void <T extends Baz> doAnotherThing(T input) {
  // similar strategy here...
}
However, this feels pretty inelegant. For one thing, it doesn't scale well to more functions / more types. For another thing, it doesn't behave nicely if I pass it the wrong types: at best I can just make it fail at runtime. So what's the best strategy here?

A little more info: while Foo and Bar both extend Baz, Baz as a whole is very broad and most of it's subclasses won't work with these methods. I do not directly control Foo and Bar, so I can't e.g. make them both implement an interface which does what I want.

if you will only be calling it on objects whose precise type is known at the call site, then you can do

Java code:
void <T extends Baz> doOneThing(T input, Consumer<T> doTheThing) {
   ...
   doTheThing.accept(input);
   ...
}

void doOneThing(Foo input) {
    doOneThing(input, Foo::doSomething);
}

void doOneThing(Bar input) {
    doOneThing(input, Bar::doSomethingElse);
}
the overloads are optional but show how to call it if you don’t use them

this has the additional advantage that you can’t call the method on a different type of Baz by accident

however, this obviously won’t work if all you know at the call site is that you have a Baz. in that case you really do just have to grit your teeth and use instanceof

Aramoro
Jun 1, 2012




Fun answer. Use reflection to workout what methods the object has and call one of them, all the downsides of using instanceof but even more inscrutable to debugging.

The Consumer interface is probably the best answer, not used it yet myself, but seems the best fit. It's a tricky situation though where you want to work on Baz objects but Foo and Bar are so diverged from it that they don't share methods that do broadly the same thing.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
inheritance should only be used for polymorphism. if you're trying to use it in order to reuse code then you done hosed up.

if you have code that is almost-but-not-quite polymorphic between foo and bar, and you really really do want to reuse your implementation, and you can't change foo and bar to make it completely polymorphic over a general interface?

then write an adapter interface that covers the things your implementation needs, and a FooAdapter and BarAdapter that wrap a Foo/Bar and conform to that interface. your real implementation only accepts the adapter type. that way your code is truly polymorphic over the interface, and the only stuff specific to one particular implementation is the adapter that deals with that specific implementation.

if you need to expand your implementation to cover more types later, just write another adapter.

Bloody
Mar 3, 2013

lol if you don't have a 20-deep inheritance tree stuffed full of 3000-line abstract classes

Captain Foo
May 11, 2004

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

Krankenstyle posted:

joking aside, its actually pronounced like the vietnamese name nguyen

nginxy face

Bloody
Mar 3, 2013

i have some c# code thats doing a lot of reflection to find everything that inherits this one base type, instantiate it, and stick it in a collection. i would like to do this without reflection, but i do not know how. like the least-worst idea i've come up with is to just do the reflection but at build-time to auto-generate out a thousand lines of constructors but that seems dumb. surely there is a better way

Captain Foo
May 11, 2004

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

Bloody posted:

i have some c# code thats doing a lot of reflection to find everything that inherits this one base type, instantiate it, and stick it in a collection. i would like to do this without reflection, but i do not know how. like the least-worst idea i've come up with is to just do the reflection but at build-time to auto-generate out a thousand lines of constructors but that seems dumb. surely there is a better way

[taps thread title]

Shaggar
Apr 26, 2006

Bloody posted:

i have some c# code thats doing a lot of reflection to find everything that inherits this one base type, instantiate it, and stick it in a collection. i would like to do this without reflection, but i do not know how. like the least-worst idea i've come up with is to just do the reflection but at build-time to auto-generate out a thousand lines of constructors but that seems dumb. surely there is a better way

you could maintain a static list of all the types by hand! generally reflection is how this is done. if you keep doing lookups, you can cache the results from the first time and then use the cached results instead

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
does c# have anything like jandex in the java world?

jandex basically it runs at compile time, does analysis of the code, and builds an index that is packaged in the jar, and you can query for super fast reflection lookups without actually doing reflection.

Bloody
Mar 3, 2013

its annoying because its poo poo thats statically known at compile-time but instead i am paying a performance penalty on startup to resolve it at runtime!!!

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
if you use the hand maintained list of classes you can add a test that fails when the list isn’t updated.

but also if startup speed isn’t an issue id just use reflection but also be really annoyed by the necessity.

DONT THREAD ON ME fucked around with this message at 16:01 on May 2, 2019

HoboMan
Nov 4, 2010

yep, seems like if the angular compiler throws an error visual studio ignores it and keeps on truckin', hosting a website with no content
if i want to see what the error is i have to open the command line and try to compile it from there

The Fool
Oct 16, 2003


HoboMan posted:

yep, seems like if the angular compiler throws an error visual studio ignores it and keeps on truckin', hosting a website with no content
if i want to see what the error is i have to open the command line and try to compile it from there

If it makes you feel any better, I have the same problem with React in VS Code + webpack dev server

CPColin
Sep 9, 2003

Big ol' smile.

DONT THREAD ON ME posted:

if you use the hand maintained list of classes you can add a test that fails when the list isn’t updated.

I added a few tests like this at a previous job. We kept having issues where people were adding values to a certain enum and not covering them with tests, so I made a test that iterated through all the values and verified via reflection that a (non-ignored!) test matched it. Got pretty entertaining calling out the devs who ignored the big "RUN THE TESTS WHEN YOU CHANGE THIS" warning before the habit really solidified in people.

I wonder nowadays if somebody's ripped those tests out since I left.

Bloody
Mar 3, 2013

dependency injection feels like an antipattern it makes it so much more difficult to actually know where poo poo is used or where its coming from

Shaggar
Apr 26, 2006
it can become an anti-pattern, but it makes things like setting up logging and data sources so much easier.

Sapozhnik
Jan 2, 2005

Nap Ghost

Bloody posted:

dependency injection feels like an antipattern it makes it so much more difficult to actually know where poo poo is used or where its coming from

Foo comes from FooImpl

Anything more complicated than that you're doing DI wrong

Sapozhnik
Jan 2, 2005

Nap Ghost
Well OK maybe you use di to set up URL routing as well or something in which case look at your di definitions file where all the routes live I guess

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

Bloody posted:

dependency injection feels like an antipattern it makes it so much more difficult to actually know where poo poo is used or where its coming from

yeah but in the end it's still constructing something with dependencies, so whether it came from the DI system or you manually constructed it it's the same.

Lutha Mahtin
Oct 10, 2010

Your brokebrain sin is absolved...go and shitpost no more!

HoboMan posted:

in retrospect i wish i had done GET /flask rather than just GET /

you cannot get ye flask

Bloody
Mar 3, 2013

CRIP EATIN BREAD posted:

yeah but in the end it's still constructing something with dependencies, so whether it came from the DI system or you manually constructed it it's the same.

yeah but reading & understanding the manually constructed code is imo much easier (and the tools are much better at it) than the DI objects-from-thin-air architecture

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

Bloody posted:

yeah but reading & understanding the manually constructed code is imo much easier (and the tools are much better at it) than the DI objects-from-thin-air architecture

this has more to do with the java inspired DI frameworks being bad than DI itself being bad.

i very much hate poo poo like guice but i use it whenever i do java

DONT THREAD ON ME fucked around with this message at 18:16 on May 2, 2019

HoboMan
Nov 4, 2010


and here i've been mostly impressed with how well intellisense has been handling javascript compared to vs 2015

HoboMan
Nov 4, 2010

how to do field masking now that jquery is haram?

e: or disallowing characters

HoboMan fucked around with this message at 20:55 on May 2, 2019

Bloody
Mar 3, 2013

shaggar what is the deal with .net remoting and is migrating to wcf the correct thing to do when stumbling upon remoting in a code base

Plorkyeran
Mar 21, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
yes wcf is the replacement for .net remoting and it’s worth making the transition

Shaggar
Apr 26, 2006

Bloody posted:

shaggar what is the deal with .net remoting and is migrating to wcf the correct thing to do when stumbling upon remoting in a code base

that was before I used .net so ive never heard of it. as with any old code unless you need to start maintaining or changing it i'd leave it the gently caress alone.

Bloody
Mar 3, 2013

i might need to refactor it anyway so i am mostly debating the degree to which i burn down the world

Shaggar
Apr 26, 2006
if its a soap thing then WCF is super easy. if its like com or something there are probably better ways to do it

Adbot
ADBOT LOVES YOU

Bloody
Mar 3, 2013

DI frameworks are a pain in the rear end. this is just singletons everywhere but with a veneer of shame on top of it

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