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
gonadic io
Feb 16, 2011

>>=
ArrowAssoc doesn't really matter that much, as it's the same as.
code:
val myMap: Map[Int, String] = Map(
  (1, "one"),
  (2, "two"),
  (3, "three"))

Adbot
ADBOT LOVES YOU

KernelSlanders
May 27, 2013

Rogue operating systems on occasion spread lies and rumors about me.
In that case you're basically back to the java version.

gonadic io
Feb 16, 2011

>>=
Except that the scala version just uses a list of pairs whereas the java version uses a bespoke MapArg22 type. Also when you get key/values out of the java you get a bespoke KeyValue object back. Java really needs tuples in the stdlib :(

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

gonadic io posted:

Except that the scala version just uses a list of pairs whereas the java version uses a bespoke MapArg22 type. Also when you get key/values out of the java you get a bespoke KeyValue object back. Java really needs tuples in the stdlib :(

It has AbstractMap.SimpleEntry. And every time I've tried to use it, I've found myself too annoyed at the excessive verbosity of Java to follow through, and end up finding some other solution.

Steve French
Sep 8, 2003

gonadic io posted:

Except that the scala version just uses a list of pairs whereas the java version uses a bespoke MapArg22 type. Also when you get key/values out of the java you get a bespoke KeyValue object back. Java really needs tuples in the stdlib :(

Thank you, this was my point, not the arrow syntactic sugar. Someone implied that there wasn't really a better alternative for the Java version, and the Scala makes it clear that with tuples and varargs there's a cleaner alternative.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
every language should have tuples

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Tuple types have always struck me as a bad idea because to some extent they defeat strong typing. A set of 2d cartesian coordinates, 2d polar coordinates, the dimensions of a rectangle or a complex number can all be represented with a pair of floats, but they have distinct semantic meanings and are not necessarily interchangeable. In a weakly-typed language I guess this is a moot issue.

gonadic io
Feb 16, 2011

>>=

Internet Janitor posted:

Tuple types have always struck me as a bad idea because to some extent they defeat strong typing. A set of 2d cartesian coordinates, 2d polar coordinates, the dimensions of a rectangle or a complex number can all be represented with a pair of floats, but they have distinct semantic meanings and are not necessarily interchangeable. In a weakly-typed language I guess this is a moot issue.

That is true, but the advantages that they have with respect to code simplicity and reuse are worth it.

Plus you can always define newtypes around your (int, int) for polar vs cartesian. Bonus points if your language enforces newtypes.

Sinestro
Oct 31, 2010

The perfect day needs the perfect set of wheels.
code:

data (Num a) => Point2D a = Point2D (a, a)

distance :: (Num a) => Point2D a -> Point2D a -> a
distance (Point2D x1 y1) (Point2D x2 y2) = sqrt $ (x1 + x2)^2 + (y1 + y2)^2

Sinestro fucked around with this message at 18:14 on Mar 14, 2016

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

Internet Janitor posted:

Tuple types have always struck me as a bad idea because to some extent they defeat strong typing. A set of 2d cartesian coordinates, 2d polar coordinates, the dimensions of a rectangle or a complex number can all be represented with a pair of floats, but they have distinct semantic meanings and are not necessarily interchangeable. In a weakly-typed language I guess this is a moot issue.

For me tuples are nearly always for when I need to stuff some things into a collection, do like 2 things to that collection, then pull things back out. In those situations, there's not a compelling reason to create something more specific. If the collection is going to live longer then the function I'm using it in, then maybe it's time for something a bit more structured. Like if I just have a bunch of keys+values and I want to sort on the keys to operate on the values in a particular order, there's a bazillion collections out there that take in <k,v> tuples and offer the key sorting for me. In that case, the collection is basically just thrown away when I'm done and I'm essentially using it as a glorified way to build a sorted queue without actually having to do the sorting (worse) myself.

KaneTW
Dec 2, 2011

The constraint on `Point2D` is useless.

Either do
code:
{-# LANGUAGE GADTs #-}
data Point2D a where
  Point2D :: Num a => a -> a -> Point2D a

distance :: Point2D a -> Point2D a -> a
or just don't do it at all and let the using functions require it when needed
code:
newtype Point2D a = Point2D (a,a)

distance :: Num a => Point2D a -> Point2D a -> a

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Steve French posted:

Thank you, this was my point, not the arrow syntactic sugar. Someone implied that there wasn't really a better alternative for the Java version, and the Scala makes it clear that with tuples and varargs there's a cleaner alternative.

I implied there wasn't a better alternative in Java, for which an example in another language isn't really contrary evidence.

brap
Aug 23, 2004

Grimey Drawer
Using tuples doesn't do anything to defeat "strong" typing but it's good to avoid consuming or producing tuples in public methods.

Any language with type aliases will let you document the intended meaning of a tuple.

KernelSlanders
May 27, 2013

Rogue operating systems on occasion spread lies and rumors about me.

Internet Janitor posted:

Tuple types have always struck me as a bad idea because to some extent they defeat strong typing. A set of 2d cartesian coordinates, 2d polar coordinates, the dimensions of a rectangle or a complex number can all be represented with a pair of floats, but they have distinct semantic meanings and are not necessarily interchangeable. In a weakly-typed language I guess this is a moot issue.

Tuple2[String, Int] is still strongly typed at both coordinates. If you want an Imag class that has two float value members re and im you should probably be creating a separate class for that along with its own arithmatic operator overloads. On the other hand, if I want to zip two lists, I shouldn't need to define a new type for the product.

Steve French
Sep 8, 2003

Subjunctive posted:

I implied there wasn't a better alternative in Java, for which an example in another language isn't really contrary evidence.

I wasn't so much arguing against your point; that said, my thought on the initial post was just as much "look at what the Java language made this library do" as much as "look at this terrible thing this library does". Additionally, given the fact that it is the standard library, I think it fairly reasonable to consider the associated language itself to be fair game. Especially considering that the only thing holding back the Map interface in this case from having a much more reasonable interface like the Scala one I Iinked to (not that the Scala collections library doesn't have it's own problems), is the lack of a compact syntax for tuples/pairs. I linked the Scala Map interface with that implication: it's totally feasible for Java to have a very similar interface, but it doesn't.

You're right that if viewed purely from the standpoint of someone implementing a Map class that has no control over the features provided by the Java language, my Scala example would not really have been contrary evidence. But it wasn't. If it were a link to a Guava class or something, and not the JDK, it would be a different story; I think the standard library is a bit of a special case.

betalarmannen
Jan 13, 2007

Pillbug
code:
class VisibilityDemo {

	private int a;
	protected int b;

	void test() {
		modify();
		System.out.println("a is " + a + ", b is " + b);
	}

	void modify() {
	}

	VisibilityDemo createOverridingVersion() {
		return new VisibilityDemo() {
			void modify() {
				a = 5;
				b = 7;
				System.out.println("a is set to " + a + ", b to " + b);
			}
		};
	}

	public static void main(String[] args) {
		VisibilityDemo original = new VisibilityDemo();

		original.createOverridingVersion().test();

		// Prints:
		// a is set to 5, b to 7
		// a is 0, b is 7
	}
}
Today I had a bug that boiled down to this. It's perfectly logical, so maybe not exactly a horror, but sure took me by surprise. (I needed the behaviour of "protected" version)

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
I would expect that to not compile. Are private variables in java always actually a weird per-subclass variable, or is that just stupid magic for anonymous classes? Both alternatives seem terrible.

KaneTW
Dec 2, 2011

Plorkyeran posted:

I would expect that to not compile. Are private variables in java always actually a weird per-subclass variable, or is that just stupid magic for anonymous classes? Both alternatives seem terrible.

IIRC weird per-subclass.

betalarmannen
Jan 13, 2007

Pillbug

Plorkyeran posted:

I would expect that to not compile. Are private variables in java always actually a weird per-subclass variable, or is that just stupid magic for anonymous classes? Both alternatives seem terrible.

The overriding modify sees the protected variable in class it is overriding (b in the new instance), but also all the variables in scope where the anonymous class is defined, that is, original.a and original.b. As "a" in new instance is invisible to overriding class, it ends up modifying original.a which it sees. It could also read all effectively final local variables in enclosing function, but not write to them...

There are ways to make it clearer, or not to compile.
code:
void modify() {
	this.a = 5;
	this.b = 7;
}
This version doesn't compile, "the field VisibilityDemo.a is not visible"

code:
void modify() {
	VisibilityDemo.this.a = 5;
	VisibilityDemo.this.b = 7;
}
This version works fine, and both variables would work like "a" in original example (members in "original" are modified, output would be "a is 0, b is 0")

qntm
Jun 17, 2009
In a nutshell, Java's methods are polymorphic but its member variables are not. And yeah, it is a horror.

CPColin
Sep 9, 2003

Big ol' smile.
On top of that, Eclipse can generate "bridge" code that make it so stuff outside of nested classes can use private members inside them. It usually doesn't affect anything, though, so you can tell Eclipse to shut up about it.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

betalarmannen posted:

The overriding modify sees the protected variable in class it is overriding (b in the new instance), but also all the variables in scope where the anonymous class is defined, that is, original.a and original.b. As "a" in new instance is invisible to overriding class, it ends up modifying original.a which it sees. It could also read all effectively final local variables in enclosing function, but not write to them...
Oh, so a and b are just from different objects. I guess that's reasonable and the horror is just implicit this, then.

baquerd
Jul 2, 2007

by FactsAreUseless
A co-worker observed there was a DNS caching issue with Kafka:

quote:

So, we could rewrite Kafka in a different language. My personal suggestion is php...

:catstare:

piratepilates
Mar 28, 2004

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



baquerd posted:

A co-worker observed there was a DNS caching issue with Kafka:


:catstare:

And that's why he had to die!

Bongo Bill
Jan 17, 2012

PHP is certainly the most Kafkaesque language.

Storysmith
Dec 31, 2006

baquerd posted:

A co-worker observed there was a DNS caching issue with Kafka:

Kafka is Java, right? Is it Kafka explicitly caching it or is it the JVM? If you're having the problem I think you are, it's not Kafka per se, more the JVM being dogshit. networkaddress.cache.ttl needs to be set to a positive value. IIRC, you need to plop that into $JAVA_HOME/jre/lib/security/java.security or something.

FamDav
Mar 29, 2008
why would wholly rewriting kafka even be a thought

you have so many options before that, including taking the kafka source, fixing your issue, and not telling anyone else about it.

piratepilates
Mar 28, 2004

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



FamDav posted:

why would wholly rewriting kafka even be a thought

you have so many options before that, including taking the kafka source, fixing your issue, and not telling anyone else about it.

Because you can do it better, duh!

I mean, how hard could it be, it's just taking some data and doing something with it, right??

TheBlackVegetable
Oct 29, 2006

piratepilates posted:

Because you can do it better, duh!

I mean, how hard could it be, it's just taking some data and doing something with it, right??

The less we think about it, the simpler it becomes!

Ika
Dec 30, 2004
Pure insanity

Sinestro posted:

code:
data (Num a) => Point2D a = Point2D (a, a)

distance :: (Num a) => Point2D a -> Point2D a -> a
distance (Point2D x1 y1) (Point2D x2 y2) = sqrt $ (x1 + x2)^2 + (y1 + y2)^2

Distance only works if x1 or x2 is 0 and y1 or y2 is 0?

chippy
Aug 16, 2006

OK I DON'T GET IT

betalarmannen posted:

code:
class VisibilityDemo {

	private int a;
	protected int b;

	void test() {
		modify();
		System.out.println("a is " + a + ", b is " + b);
	}

	void modify() {
	}

	VisibilityDemo createOverridingVersion() {
		return new VisibilityDemo() {
			void modify() {
				a = 5;
				b = 7;
				System.out.println("a is set to " + a + ", b to " + b);
			}
		};
	}

	public static void main(String[] args) {
		VisibilityDemo original = new VisibilityDemo();

		original.createOverridingVersion().test();

		// Prints:
		// a is set to 5, b to 7
		// a is 0, b is 7
	}
}
Today I had a bug that boiled down to this. It's perfectly logical, so maybe not exactly a horror, but sure took me by surprise. (I needed the behaviour of "protected" version)

I haven't used Java for a few years so I'm a bit rusty... what does the createOverridingVersion() method actually do? Is that returning a new VisibilityDemo() instance, but with the modify() method overriden? So you essentially end up with two objects, ostensibly of the same type, but one with a differently behaving modify()? It seems crazy that you can even do that.

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.

chippy posted:

I haven't used Java for a few years so I'm a bit rusty... what does the createOverridingVersion() method actually do? Is that returning a new VisibilityDemo() instance, but with the modify() method overriden? So you essentially end up with two objects, ostensibly of the same type, but one with a differently behaving modify()? It seems crazy that you can even do that.
It's creating an anonymous class that extends VisibilityDemo and returing a new instance of it. Just a more concise version of this:
code:
VisibilityDemo createOverridingVersion() {
	class Foo extends VisibilityDemo {
		void modify() {
			a = 5;
			b = 7;
			System.out.println("a is set to " + a + ", b to " + b);
		}
	};
	return new Foo();
}

chippy
Aug 16, 2006

OK I DON'T GET IT
Right, ok. I didn't realise it was anonymous, I guess it was the 'return new VisibilityDemo()' that confused me.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

Ika posted:

Distance only works if x1 or x2 is 0 and y1 or y2 is 0?

What?

Winter Stormer
Oct 17, 2012

pre:
distance (Point2D x1 y1) (Point2D x2 y2) = sqrt $ (x1 + x2)^2 + (y1 + y2)^2
How far is (1,1) from (1,1)?

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

Winter Stormer posted:

pre:
distance (Point2D x1 y1) (Point2D x2 y2) = sqrt $ (x1 + x2)^2 + (y1 + y2)^2
How far is (1,1) from (1,1)?

Oh, right

piratepilates
Mar 28, 2004

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



Came across this discussion on Twitter about removing issues from github and forcing everything to be a PR instead: https://gist.github.com/ryanflorence/8a62abea562ca2896dee

I mean it's an interesting idea and I see why they would like to do it, but it feels like boasting that the amount of negative feedback about your project had gone down after you removed the feedback form from your site.

ynohtna
Feb 16, 2007

backwoods compatible
Illegal Hen

Ryan Florence posted:

This isn't a rigorous statistic, but I'm pretty sure these are 99% of the issues on Github.
:rolleyes:

Save yer self-preening quips for the conference stages, Ryan.

piratepilates posted:

I mean it's an interesting idea and I see why they would like to do it, but it feels like boasting that the amount of negative feedback about your project had gone down after you removed the feedback form from your site.

Exactly.

Sinestro
Oct 31, 2010

The perfect day needs the perfect set of wheels.

Ika posted:

Distance only works if x1 or x2 is 0 and y1 or y2 is 0?

Amazingly the code I wrote while waiting in a line for coffee isn't perfectly correct. :smithicide:

Adbot
ADBOT LOVES YOU

xzzy
Mar 5, 2009

I too want to install gates to further restrict feedback when at best a couple percent of everyone who's ever cloned the repo will bother to try and report an issue.

Most people are going to be all "compile failed? pfft rm -rf and move on to the next option."

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