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
Munkeymon
Aug 14, 2003

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



Career paused to raise kids?

Adbot
ADBOT LOVES YOU

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"
Suffering to maintain legacy software can be fairly lucrative...

But unfortunately for them, I don't think there are that many people whose business model relies on keeping Win ME installations running.

canis minor
May 4, 2011

DHL, why can't you respond with the same response to the same request? Why do you "Yes, we're shipping to this destination - here are the prices" one time, and in a second you do "Nope, shipping here is not possible"

Pavlov
Oct 21, 2012

I've long been fascinated with how the alt-right develops elaborate and obscure dog whistles to try to communicate their meaning without having to say it out loud
Stepan Andreyevich Bandera being the most prominent example of that

loinburger posted:

I'm working on a Java/Spring application and discovered that some of my "singleton" constructors were being called twice (I added an ActiveMQ persistent queue, and JMX was giving me an InstanceAlreadyExistsException on its BrokerService). It turns out that we're creating two copies of the ApplicationContext and hence two copies of the program's internal state because, well, just because.

Spring you say? Then obviously you should make use of the AbstractSingletonProxyFactoryBean. It's right there in the description: "Convenient proxy factory bean superclass for proxy factory beans that create only singletons."

No need to thank me.

Pavlov fucked around with this message at 18:42 on Aug 28, 2015

tyrelhill
Jul 30, 2006
Hahaha gotta love Java, 5 design pattern names in a single class name.

Sedro
Dec 31, 2008

Pavlov posted:

Spring you say? Then obviously you should make use of the AbstractSingletonProxyFactoryBean. It's right there in the description: "Convenient proxy factory bean superclass for proxy factory beans that create only singletons."

No need to thank me.
Oh boy, that's so convenient! It was probably posted here already but someone made a game of this.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

Sedro posted:

Oh boy, that's so convenient! It was probably posted here already but someone made a game of this.

Good grief i went 0/9 before i gave up ;_;

No Safe Word
Feb 26, 2005

Sedro posted:

Oh boy, that's so convenient! It was probably posted here already but someone made a game of this.

"Ha ha it shouldn't be that hard to pick the made up one"

:stonk:

Pavlov
Oct 21, 2012

I've long been fascinated with how the alt-right develops elaborate and obscure dog whistles to try to communicate their meaning without having to say it out loud
Stepan Andreyevich Bandera being the most prominent example of that

Sedro posted:

Oh boy, that's so convenient! It was probably posted here already but someone made a game of this.

You are a saint.

substitute
Aug 30, 2003

you for my mum
code:

/*-------------------------------------------------------
	BEGIN: CONSTR & INIT
-------------------------------------------------------*/
// constr:
// Proper constructor declaring and intializing data members.
proto.constr=function constr(data){
	//trace("DetailDisplay: CONSTR");
	try{
	// call super class
	data=DetailDisplay._super.constr.call(this,data);

	// Declare local variables needed.

	// BEGIN: data members
	this.thumbImg;
	this.wtb;
	// END: data members

	// BEGIN: constant data members
	// END: constant data members

	return data;
	}catch(e){GNS._error("DetailDisplay: CONSTR: "+e);}
};

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

substitute posted:

code:

/*-------------------------------------------------------
	BEGIN: CONSTR & INIT
-------------------------------------------------------*/
// constr:
// Proper constructor declaring and intializing data members.
proto.constr=function constr(data){
	//trace("DetailDisplay: CONSTR");
	try{
	// call super class
	data=DetailDisplay._super.constr.call(this,data);

	// Declare local variables needed.

	// BEGIN: data members
	this.thumbImg;
	this.wtb;
	// END: data members

	// BEGIN: constant data members
	// END: constant data members

	return data;
	}catch(e){GNS._error("DetailDisplay: CONSTR: "+e);}
};


Somebody using their college's project templates in production code?

substitute
Aug 30, 2003

you for my mum

LeftistMuslimObama posted:

Somebody using their college's project templates in production code?

Yes, all over the place and for about 6 years. But this fuckhead consultant (which is putting it generously) is finally gone!

We (mostly I) will still have to deal with all the lingering garbage though, until a large group of flagship sites are completely redone. Hoping that happens next year.

loinburger
Jul 10, 2004
Sweet Sauce Jones

Pavlov posted:

Spring you say? Then obviously you should make use of the AbstractSingletonProxyFactoryBean. It's right there in the description: "Convenient proxy factory bean superclass for proxy factory beans that create only singletons."

No need to thank me.

When I first inherited the project we had about a dozen godawful class names that were shadowing godawful Spring class names, and we were using both our classes and the Spring classes in the project so you couldn't tell which was being used without looking at the imports. The only one I never bothered to properly fix is the PropertyPlaceholderConfigurerCustom which used to shadow the PropertyPlaceholderConfigurer.

loinburger fucked around with this message at 23:02 on Aug 28, 2015

The Laplace Demon
Jul 23, 2009

"Oh dear! Oh dear! Heisenberg is a douche!"

loinburger posted:

I'm working on a Java/Spring application and discovered that some of my "singleton" constructors were being called twice (I added an ActiveMQ persistent queue, and JMX was giving me an InstanceAlreadyExistsException on its BrokerService). It turns out that we're creating two copies of the ApplicationContext and hence two copies of the program's internal state because, well, just because.

Pavlov posted:

Spring you say? Then obviously you should make use of the AbstractSingletonProxyFactoryBean. It's right there in the description: "Convenient proxy factory bean superclass for proxy factory beans that create only singletons."

No need to thank me.

:bravo:

EDIT: Seriously though, just add another layer of abstraction to getting an "instance" of your singleton and handle the single initialization there, i.e. create a SingletonProxyFactory™ and make it a Spring Bean for convenience. And since all this initialization logic is independent of what the class does, let's pull it out into an Abstract class. (disclaimer: I have no idea how an AbstractSingletonProxyFactoryBean is actually used).

The Laplace Demon fucked around with this message at 07:09 on Aug 29, 2015

Pavlov
Oct 21, 2012

I've long been fascinated with how the alt-right develops elaborate and obscure dog whistles to try to communicate their meaning without having to say it out loud
Stepan Andreyevich Bandera being the most prominent example of that

The Laplace Demon posted:

I have no idea how an AbstractSingletonProxyFactoryBean is actually used.

I'm pretty sure it's part of a suite of tools used to cause EE developers bloody their heads against their desks.

loinburger
Jul 10, 2004
Sweet Sauce Jones

The Laplace Demon posted:

:bravo:

EDIT: Seriously though, just add another layer of abstraction to getting an "instance" of your singleton and handle the single initialization there, i.e. create a SingletonProxyFactory™ and make it a Spring Bean for convenience. And since all this initialization logic is independent of what the class does, let's pull it out into an Abstract class. (disclaimer: I have no idea how an AbstractSingletonProxyFactoryBean is actually used).

The problem is that as far as I know the two ApplicationContexts we're creating can't talk to each other during initialization - if I used a [...]ProxyBean to proxy the singleton creation then I'd just wind up creating a separate [...]ProxyBean for each ApplicationContext and I'd still have two sets of singletons.

Ideally we'd just create a single ApplicationContext, or barring that we'd create two ApplicationContexts with disjoint sets of beans so there wouldn't be any name conflicts or wasted duplicate resources; however I don't yet know what the justification was for creating the two ApplicationContexts in the first place and so I don't know which solution we should go with. In the meantime I've created separate configs for the two ApplicationContexts, the differences being that their ActiveMQ broker names, queue names, database directories, and ports are different.

DICTATOR OF FUNK
Nov 6, 2007

aaaaaw yeeeeeah
and now for the latest iteration of Javascript Owns™:

https://jsfiddle.net/Ly351fnw/

Definitely added a list length checker to that one :v:

vOv
Feb 8, 2014

What do you think Math.max() should return?

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

vOv posted:

What do you think Math.max() should return?

Agreed, when there are no items there are two possible approaches that make sense. That is one of them, the other is throwing.

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.

Hammerite posted:

Agreed, when there are no items there are two possible approaches that make sense. That is one of them, the other is throwing.

Javascript doesn't throw for divide by zero, or trying to work with NaNs as if they are numbers (so 5/NaN = NaN.) It's really obnoxious when trying to do numerical stuff in javascript.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Douglas Crockford said that the sticky NaN was one of JavaScript's best features.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

Bruegels Fuckbooks posted:

Javascript doesn't throw for divide by zero, or trying to work with NaNs as if they are numbers (so 5/NaN = NaN.) It's really obnoxious when trying to do numerical stuff in javascript.

5.f / NaN == NaN though, that's how it works. Normal operations always produce quiet NaNs. It's fine to say "double precision IEEE754 fp was and remains a poor choice for all of JS's arithmetic", but it's senseless to kvetch that it implements it correctly in this case.

Vanadium
Jan 8, 2005

Coding horror: Whenever I reach for max(x, y), it's because I want to use the value of x, but I want it to be y at maximum. Shortly after I usually realize my error.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

Vanadium posted:

Coding horror: Whenever I reach for max(x, y), it's because I want to use the value of x, but I want it to be y at maximum. Shortly after I usually realize my error.

The word you're looking for is 'clamp' :)

Vanadium
Jan 8, 2005

Well, it's really just "min" but it always seems backwards to me :saddowns:

SupSuper
Apr 8, 2009

At the Heart of the city is an Alien horror, so vile and so powerful that not even death can claim it.

Vanadium posted:

Well, it's really just "min" but it always seems backwards to me :saddowns:
That's probably because you interpret "max" as "setting the max value" as opposed to "getting the local max" so "max(x, MAX) means x can never exceed MAX right???" and yeah I do it too. :v:

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Yeah, I usually write an absolutely confusing function for this.

JavaScript code:
function clamp(v, min, max) {
    return Math.min(max, Math.max(min, v));
}

Suspicious Dish
Sep 24, 2011

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

Blotto Skorzany posted:

5.f / NaN == NaN though, that's how it works.

false

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
A figurative ==, obviously any comparison with NaN will return false :v:

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Blotto Skorzany posted:

A figurative ==, obviously any comparison with NaN will return false :v:

except of course NaN != NaN, which will return true :q:

NihilCredo
Jun 6, 2011

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

Suspicious Dish posted:

Yeah, I usually write an absolutely confusing function for this.

JavaScript code:
function clamp(v, min, max) {
    return Math.min(max, Math.max(min, v));
}

Same except I call it "bound". Or "Bounded" if it's an extension method.

b0lt
Apr 29, 2005

NihilCredo posted:

Same except I call it "bound". Or "Bounded" if it's an extension method.

It's called saturate :argh:

Xerophyte
Mar 17, 2008

This space intentionally left blank

b0lt posted:

It's called saturate :argh:

Not really. saturate(x) is clamp(x, 0.0, 1.0) in shading languages. Well, in the shading languages that have a saturate function and in ARB, anyhow. It's not a very well-chosen name -- I would have expected saturate it to make a color more saturated, instead of less -- but it's the one we've got.

Those are the standard names in graphics so it's probably best to stick with them in that context to not confuse people. In contexts that aren't graphics then you can call your equivalent functions whatever, really.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Xerophyte posted:

Not really. saturate(x) is clamp(x, 0.0, 1.0) in shading languages. Well, in the shading languages that have a saturate function and in ARB, anyhow. It's not a very well-chosen name -- I would have expected saturate it to make a color more saturated, instead of less -- but it's the one we've got.

https://en.wikipedia.org/wiki/Saturation_arithmetic

sarehu
Apr 20, 2007

(call/cc call/cc)
When I was some scrub teenager I needed a clamp function and named it "clamp" never having seen such a function before, so that seems like the right name to me.

Pavlov
Oct 21, 2012

I've long been fascinated with how the alt-right develops elaborate and obscure dog whistles to try to communicate their meaning without having to say it out loud
Stepan Andreyevich Bandera being the most prominent example of that
I've seen it as clamp before in a graphics library too.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
I like "mid" because it's only three letters and fits nicely with min and max.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀

Plorkyeran posted:

I like "mid" because it's only three letters and fits nicely with min and max.

Mid sounds like it gets the mean or median of a set of values.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Dr. Stab posted:

Mid sounds like it gets the mean or median of a set of values.

Getting the median of three values is exactly what the clamp function does :ssh:

Adbot
ADBOT LOVES YOU

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



Mid is how you get a substring in a string given beginning and end indices in VB6. That's now burned in my brain.

You can use it still today in VB.NET or maybe even C# too.

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