News for hackers. Stuff that matters.
Re:Go After 2 Years in Production by howeman on Tuesday August 27, 2013 @03:37PM (#6285704)
It's not quite that bad in Go,

(-b + math.Sqrt(bb - 4ac)) / (2 a)

though if you're using a ton of matrices it could be.

I for one have found Go great for computing. The really quick compile times with static checking plus the composability are great. It definitely depends though; while the native concurrency is great there aren't a lot of easy solutions for non-shared memory computations. (I saw an MPI package at one point, but I haven't tried to use it)

Re:Go After 2 Years in Production by rprospero on Tuesday August 27, 2013 @06:39PM (#6286739)
It's more than just matrices, though. For instance, I have a little library that propagates uncertainty for me. Without operator overloading, I'm back to descending into the rpn hole from my example.

Another poster pointed out unit analysis. I've done this before with custom types that keep track of the units on measurements.

Since you mentioned parallelization, that's another fun toy I've played with. By overloading the operators for an object that defines a snippet of OpenCL code, it's possible to push these snippets through pre-existing functions and have it return a final OpenCL function. You then call that returned function on your arrays of data to run everything through your GPU with just three lines of code changes from the sequential.

Operator overloading is more than just adding matrices. It's a powerful technique that comes in handy almost any time that you're working heavily with numerical data. Of course, it's also dangerous as hell in the wrong hands. The code for the OpenCL example was actually some pretty terrible code that did extremely non-intuitive things during value comparisons.

Re:Go After 2 Years in Production by howeman on Wednesday August 28, 2013 @02:35AM (#6288339)
Operator overloading can certainly do good things. Not going to argue with you there. Though, in the case of units, you can actually go a long way with that (http://play.golang.org/p/iCqB2euJj8). It's not perfect, you have to do some function calls to multiply units of differing type correctly, but you do gain all the proper compile-time safety, and you don't need to do all sorts of method calls.

What are you doing with uncertainty that you can do operator overloading with? You usually want to do Bayes rule with probabilities, but that gets intractable fast.

Re:Go After 2 Years in Production by howeman on Tuesday August 27, 2013 @05:25PM (#6286404)
Sorry, new to posting on HN. How do I get asterisk literals?
Re:Go After 2 Years in Production by prodigal_erik on Tuesday August 27, 2013 @06:48PM (#6286780)
https://news.ycombinator.com/formatdoc says two leading spaces formats code verbatim:

  (-b + math.Sqrt(b*b - 4*a*c)) / (2*a)
Re:Go After 2 Years in Production by sampo on Tuesday August 27, 2013 @07:34PM (#6287043)
Leave a whitespace after the asterisk: 1 * 2 * 3 = 6

https://news.ycombinator.com/formatdoc

Re:Go After 2 Years in Production by scott_s on Tuesday August 27, 2013 @06:41PM (#6286748)
Make sure there are spaces on both sides. Asterisk: * (plain asterisk surround by spaces). Italics: foo ('foo' surrounded by asterisks).