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
rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

TOPS-420 posted:

thank you golang for making incorrect floating point rounding a problem in tyool 2017

https://www.cockroachlabs.com/blog/rounding-implementations-in-go/

at first i was going to defend go and say that rounding is annoying and getting exact fp reproducibility is difficult in any language

but no, apparently we are talking about normal, user-level rounding, and go just declines to provide a function to do it, :wtc:

Adbot
ADBOT LOVES YOU

feedmegin
Jul 30, 2008

Sapozhnik posted:

maybe it's different inside apple idk, i haven't come across any major open source c projects that abuse preprocessor macros to that extent.

This is from a few weeks back, but I'm guessing you've never done any Gtk/Gnome programming?

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde
more like doh-lang

Max Facetime
Apr 18, 2009

rjmccall posted:

at first i was going to defend go and say that rounding is annoying and getting exact fp reproducibility is difficult in any language

but no, apparently we are talking about normal, user-level rounding, and go just declines to provide a function to do it, :wtc:

floats are fun and that blog inspired me to polish up my round half up function

works in Java and IEEE floating point, easy prey for misguided compilers

Java code:
	public static double roundHalfUp(double value) {
		// parts with CAREFULLY can compile to wrong code in broken compilers
		
		// next integer after largest positive fractional double, even
		double allIntsEven = 4503599627370496.0; // 2^52
		// next integer after largest positive fractional double, but odd
		double allIntsOdd = 4503599627370497.0; // 2^52 + 1
		
		// CAREFULLY, turn signed zeroes and other values to infinities of the
		// same sign, by using 1/0 => INF and 1/(-0) => -INF
		double negative = 1.0 / (0.0 * value) < 0.0 ? -1.0 : 1.0;
		
		// if needed flip the sign to work with positive values only
		double absValue = value * negative;
		
		// avoid round-off with large values which are already integers
		double use = absValue < allIntsEven ? 1.0 : 0.0;
		
		// CAREFULLY, induce round-off in an intermediate value of the same
		// evenness as input, ties broken towards even values
		// CAREFULLY, flip evenness of intermediate value and repeat
		double even = use * -allIntsEven + (use * allIntsEven + absValue);
		double odd = use * -allIntsOdd + (use * allIntsOdd + absValue);
		
		// choose larger of tie-breaks of unknown evenness
		double up = even > odd ? even : odd;
		
		// CAREFULLY, add back sign or use special values as is, by using
		// INF-INF <=> -INF-(-INF) <=> NaN-NaN => NaN != 0.0
		double signed = value - value == 0.0 ? up * negative : value;
		return signed;
	}
	public static void main(String[] args) {
		double[][] tests = {
			{ -0.49999999999999994, -0.0 },
			{ -0.5, -1.0 },
			{ -0.5000000000000001, -1.0 },
			{ 0.0, 0.0 },
			{ 0.49999999999999994, 0.0 },
			{ 0.5, 1.0 },
			{ 0.5000000000000001, 1.0 },
			{ 1.390671161567e-309, 0.0 },
			{ 2.2517998136852485e+15, 2.251799813685249e+15 },
			{ 4.503599627370497e+15, 4.503599627370497e+15 },
			{ Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY },
			{ Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY },
			{ Double.NaN, Double.NaN },
			{ -0.0, -0.0 },
		};
		for(double[] test : tests) {
			double got = roundHalfUp(test[0]);
			boolean ok = Double.doubleToLongBits(got) == Double.doubleToLongBits(test[1]);
			System.out.printf("%22s ~%s %22s %s= %22s\n", test[0], ok ? '=' : '?', got, ok ? '=' : '!', test[1]);
		}
	}

cinci zoo sniper
Mar 15, 2013




is there something fundamental about programming language design that there are, i think, no modern jit-compiled or interpreted languages with strong type system?

gonadic io
Feb 16, 2011

>>=
I think you really confusing strong/weak typing (how much the compiler lets you get away with) vs static/dynamic typing (whether it's checked at compile or runtime).

Python is strongly typed for example, if the types don't match you get errors.

There's not really any examples of static but weak typed languages - c might count because you can cast anything to anything but in general if you have a compiler and types then you might as well use the compiler to check types.

You don't have to though - haskell has an option to defer type errors to runtime only on executed code for example.

Cybernetic Vermin
Apr 18, 2005

strong type systems mix poorly with dynamic loading etc., need to then explicitly define interfaces (e.g. sml-stype modules). at that point it gets complicated enough that it is more a matter of no such languages really gaining traction

the greater mystery is really why it is so hard for the die-hard fans of truly advanced type systems to understand that it is invariably very poor hci, and wont ever catch on in a capacity where it needs to be possible to hire a person off the street to work with it (without assuming passion or excessive talent, just normal hire-a-suitable-enough-person-to-do-things-for-the-money).

Sinestro
Oct 31, 2010

The perfect day needs the perfect set of wheels.

Cybernetic Vermin posted:

the greater mystery is really why it is so hard for the die-hard fans of truly advanced transportation systems to understand that it is invariably very poor hvi, and wont ever catch on in a capacity where it needs to be possible to hire a person off the street to drive it (without assuming passion or excessive talent, just normal hire-a-suitable-enough-person-to-do-things-for-the-money).

it's a good thing that we still go around with horses and buggies, because early cars were complicated!

unless you're putting "writing code that doesn't just happen to not be broken for the exact case I'm screwing around with in my REPL/toy test program" as beyond an average programmer, there is no reason that a good type system can't succeed, they've just been almost entirely present in research-type languages, where there's more focus on novel developments than on perfectly refined interactions.

cinci zoo sniper
Mar 15, 2013




gonadic io posted:

I think you really confusing strong/weak typing (how much the compiler lets you get away with) vs static/dynamic typing (whether it's checked at compile or runtime).

Python is strongly typed for example, if the types don't match you get errors.

There's not really any examples of static but weak typed languages - c might count because you can cast anything to anything but in general if you have a compiler and types then you might as well use the compiler to check types.

You don't have to though - haskell has an option to defer type errors to runtime only on executed code for example.

yeah im not fluent with terminology, just musing why python 3 type annotations are not going past being just suggestions, which seems to be what cybernetic vermin talks about

MononcQc
May 29, 2007

cinci zoo sniper posted:

is there something fundamental about programming language design that there are, i think, no modern jit-compiled or interpreted languages with strong type system?

Lua?

I guess you can argue on whether it is strong-typed, but generally you can't do poo poo like add strings and integers together (aside from the proper operator) and it would be regarded as dynamic and strong-typed.

cinci zoo sniper
Mar 15, 2013




http://adv-r.had.co.nz/Functions.html i have so many questions

Vanadium
Jan 8, 2005

Not sure how i feel about categorizing a type system by the availability of implicit conversion operators or w/e

I feel like weakly typed it when youre bash and everything is a string, or some asm where everything is a word

Cybernetic Vermin
Apr 18, 2005

Sinestro posted:

it's a good thing that we still go around with horses and buggies, because early cars were complicated!

unless you're putting "writing code that doesn't just happen to not be broken for the exact case I'm screwing around with in my REPL/toy test program" as beyond an average programmer, there is no reason that a good type system can't succeed, they've just been almost entirely present in research-type languages, where there's more focus on novel developments than on perfectly refined interactions.

the reason is that most code in the world is written by full-time java programmers who would struggle to write a generic class themselves, and it is not the people that will change

Athas
Aug 6, 2007

fuck that joker

cinci zoo sniper posted:

is there something fundamental about programming language design that there are, i think, no modern jit-compiled or interpreted languages with strong type system?

Java? F#? Kotlin? Not sure if these are modern enough.

Writing a JIT is so difficult that only languages with massive support can get away with it (wit LuaJIT the most important exception). And for most statically typed languages, you can just write a conventional compiler and get performance as good (or better) at a fraction of the complexity.

cinci zoo sniper
Mar 15, 2013




you compile java though, so maybe i should've not mentioned jit. basically i wish a statically typed python would be real, and i should probably read some compsci book so i dont pull terms out of my rear end

gonadic io
Feb 16, 2011

>>=
yeah basically none of these terms are concretely defined or languages categorised exactly anyway. you're right about it being a trend though, if not a rule. honestly i think it's just that people who don't want to (can't be botherted to) write a compiler they won't write a static analyser into the lang either, but it you have written a compiler it's a lot less effort to put types in.

cinci zoo sniper
Mar 15, 2013




makes sense. any light programming language theory read suggestions, speaking of? keep in mind ive got just the physics background

MononcQc
May 29, 2007

cinci zoo sniper posted:

you compile java though, so maybe i should've not mentioned jit. basically i wish a statically typed python would be real, and i should probably read some compsci book so i dont pull terms out of my rear end

I mean PyPy is a JIT for Python if that's still relevant to the JIT discussion

Shaggar
Apr 26, 2006

cinci zoo sniper posted:

you compile java though, so maybe i should've not mentioned jit. basically i wish a statically typed python would be real, and i should probably read some compsci book so i dont pull terms out of my rear end

for java and c# there are 2 compilation phases. The first is your traditional, ahead of time compilation which is what you're doing with your IDE/build tools. This generates a pile of bytecode that can run on top of the language's VM (jvm for java, clr for c#). Then when the bytecode is executed on the vm, the JIT runs compilations based on the current running environment and the result is optimized for the local platform. This could be any kind of os or hardware optimizations.

cinci zoo sniper
Mar 15, 2013




MononcQc posted:

I mean PyPy is a JIT for Python if that's still relevant to the JIT discussion

pypy i know of, even if i dont like significant 3rd party deps. now typing though, there are annotations in 3.x and there is that one library that mimicks them, but nothing strong afaik

tef
May 30, 2004

-> some l-system crap ->

cinci zoo sniper posted:

you compile java though, so maybe i should've not mentioned jit. basically i wish a statically typed python would be real, and i should probably read some compsci book so i dont pull terms out of my rear end

golang is close tbh

garbage collection
structural types

but yeah

cinci zoo sniper
Mar 15, 2013




tef posted:

golang is close tbh

garbage collection
structural types

but yeah

golang would be nice if not for whole idiotic philosophy that results in generics being accessible to vip club only. not that it's the only problem, but the language isn't held back by more than the opinions of chief designers

Shaggar
Apr 26, 2006
the people behind go are all idiots so idk why you would go near it

tef
May 30, 2004

-> some l-system crap ->

cinci zoo sniper posted:

is there something fundamental about programming language design that there are, i think, no modern jit-compiled or interpreted languages with strong type system?

no

it's kinda the opposite

with static vs dynamic, modern compilers and jits are replacing full ahead of time knowledge with inference and profiling

and the technology behind the jvm was designed for smalltalk and self, dynamic languages

weak vs strong is basically how intentional vs accidental your subclassing is

like, you can have a terrible mess of implicit casts in any languages, but structural (or more duck typed) languages often come with things that respond to different protocols (a string is a list, and a bool too!)

java having only one type of null is an example of weak typing

then you've got nominative vs structural

or 'do they have the same name' vs 'do they have the same features'



anyway, people are doing JIT over C, specifically to lower FFI costs :v

tef
May 30, 2004

-> some l-system crap ->

cinci zoo sniper posted:

golang would be nice if not for whole idiotic philosophy that results in generics being accessible to vip club only. not that it's the only problem, but the language isn't held back by more than the opinions of chief designers

lol you read one tweet and somehow they're keeping generics from the masses

Soricidus
Oct 21, 2010
freedom-hating statist shill

cinci zoo sniper posted:

you compile java though, so maybe i should've not mentioned jit. basically i wish a statically typed python would be real, and i should probably read some compsci book so i dont pull terms out of my rear end

both java and python are first compiled to bytecode and then executed in a vm. the only difference is that python handles the compilation stage transparently if you give it source code to run

tef
May 30, 2004

-> some l-system crap ->
java: generics were added after GJ/Pizza

c#: generics come out in 2.0

go: hey, so for 2.0 we're wondering about how to do generics, and nothing people have proposed have worked out

like

you have the c++ programmers who want generics, i.e they want to be able to do move constructors and raii

you also have a bunch of people used to java etc who just want a Set<X>

but you also have the functional weenies who want HKTs

like, you have massive co-variance and contra-variance problems to solve when it comes to structural types

it's not generics, it's implementing them in a way that makes sense with the interfaces


and well, the compiler, on the inside, doesn't have to deal with these constraints

a parameterized type is one thing but how that interplays with type inference is actually kinda hard

Mr SuperAwesome
Apr 6, 2011

im from the bad post police, and i'm afraid i have bad news

cinci zoo sniper posted:

you compile java though, so maybe i should've not mentioned jit. basically i wish a statically typed python would be real, and i should probably read some compsci book so i dont pull terms out of my rear end

i write python for my job and the bigger our codebase gets the more i'd like to be using something actually statically typed + with enforced interfaces etc

ABCs are nice, type hinting is largely uselss, interfaces are kinda a fudge

it'd be nice to have the compiler catch ur mistakes and ur coworkers instead of.... QA/production

Mr SuperAwesome
Apr 6, 2011

im from the bad post police, and i'm afraid i have bad news
basically i want to write C# i guess

cinci zoo sniper
Mar 15, 2013




tef posted:

lol you read one tweet and somehow they're keeping generics from the masses

what else should i infer from 24/7 anti-go circlejerk everywhere. irl ive seen exactly one go project, and it was some college class project web game backend :shrug:

anyways yikes i only wanted to wonder about static typing in python, r, and similar languages :ohdear:

cinci zoo sniper
Mar 15, 2013




Mr SuperAwesome posted:

i write python for my job and the bigger our codebase gets the more i'd like to be using something actually statically typed + with enforced interfaces etc

same only my python project is not exactly a job per se, and the codebase is probably laughable by any meaningful standard. same for the job though, but thank god i have to only write scripts in r, not extend r

Shaggar
Apr 26, 2006

Mr SuperAwesome posted:

basically i want to write C# i guess

or java. mostly c# tho.

motedek
Oct 9, 2012

cinci zoo sniper posted:

what else should i infer from 24/7 anti-go circlejerk everywhere. irl ive seen exactly one go project, and it was some college class project web game backend :shrug:

anyways yikes i only wanted to wonder about static typing in python, r, and similar languages :ohdear:

i asked hadley at a meetup whether R would be better with types, he said no

TOPS-420
Feb 13, 2012

julia is a jit-compiled language with a cool multimethod-based type system. seems to be getting some early traction with the matlab crowd

ocaml has a p nice interpreter/repl and all the pointless academic type system features

cinci zoo sniper
Mar 15, 2013




motedek posted:

i asked hadley at a meetup whether R would be better with types, he said no
im not surprised, if he is anything his programs are then we have radically different opinions on things

Sapozhnik
Jan 2, 2005

Nap Ghost
doesn't julia have some weird mix of 1-based and 0-based indexing

1-based indexing is the dumbest thing

hepatizon
Oct 27, 2010

Sapozhnik posted:

doesn't julia have some weird mix of 1-based and 0-based indexing

1-based indexing is the dumbest thing

inconsistent indexing is much worse than 1-based indexing

in a language with good built-in functions for list traversal, the indexing scheme reduces to an HCI problem

The Laplace Demon
Jul 23, 2009

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

tef posted:

you have the c++ programmers who want generics, i.e they want to be able to do move constructors and raii


uh no, c++ templates are completely orthogonal to move constructors and raii. templates automate the process of copy pasting the code for FooSet and renaming all the Foo to Bar

call a templated method with a new type? generate a completely separate implementation. anyways, contravariance and covariance are problems for languages with type hierarchies, not golang

VikingofRock
Aug 24, 2008




IMO allow arbitrary indexing :2bong:

Adbot
ADBOT LOVES YOU

gonadic io
Feb 16, 2011

>>=

rust could even make this zero-cost for regular int indexing, it'd just get inlined.

brb building library.

e: this package gives you n-dimensional indices: https://docs.rs/ndarray/0.10.0/ndarray/
and i'm not sure there's other use cases for arbitrarily-typed indices.

gonadic io fucked around with this message at 18:06 on Jul 17, 2017

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