News for hackers. Stuff that matters.
Re:A farewell note to a programming language by lostcolony on Thursday December 04, 2014 @11:48AM (#8700145)
Mixing an imperative developer with a functional developer? That's asking for trouble. You'll have to be converting between mutable and immutable data structures anywhere the two interact. Or forcing the imperative developer to be largely functional due to the immutable data structures everywhere that prevent him from using imperative approaches. Or forcing the functional developer to write in a largely imperative style due to the mutable data structures that prevent copying from being efficient, and can be mutated any time they pass out of his/her code.

Or to put it another way; Scala as an idea may be fine; you can mix imperative and functional together, by picking which data structure and approach for a given problem is 'right'. But in a team environment? Touching someone else's code in a particular paradigm means you have to be familiar with, and expect, that paradigm. You can come up with a team that agrees on what paradigm everything must be written in (and that can be anywhere on the continuum), but you can't mix and match and expect developers to not have to learn every paradigm in use.

Re:A farewell note to a programming language by lmm on Thursday December 04, 2014 @12:23PM (#8700351)
Not "everything"; each codebase needs a particular style sure, but the great advantage of Scala is that your skanky 5-minute scripts and your carefully engineered five 9s backends can each be written in an appropriate style, and share the same libraries where that makes sense.
Re:A farewell note to a programming language by lostcolony on Thursday December 04, 2014 @12:36PM (#8700425)
Imperative Bob needs to fix a bug in Functional Dave's code. Or just call it from his imperative code with an appropriate data structure. Or write a module for Functional Dave to call.

All of those require being familiar with the functional paradigm, or a data type conversion. And vice versa.

Sure, for code that doesn't interact, or that does only through an interface not defined by the language (i.e., through the OS, through sockets, whatever), the issues in style don't exist, and Scala kinda makes sense as a "single language that tries to be all things to all people". But on a shared codebase, with a 'team style', per the OP, that allows people to use what they're most familiar with...mixing paradigms is going to cause problems, and will force each dev to learn each paradigm in use.

Please note I'm not saying there's no benefit to mixing paradigms, or that a language that includes multiple paradigms is bad, but rather that by allowing more paradigms the codebase you increase the breadth of knowledge necessary to work on that codebase, such that letting people stay in their comfortable, single paradigm bubble is impossible, at least if you want them directly interacting with the code written by someone else in a different paradigm.

Re:A farewell note to a programming language by tel on Thursday December 04, 2014 @01:01PM (#8700596)
The ST monad would like a work with you :)
Re:A farewell note to a programming language by lostcolony on Thursday December 04, 2014 @02:47PM (#8701232)
Which doesn't help the imperative programmer who is having to interact with functional code.

And an ST monad makes no sense unless you're interacting with imperative code (obviously, hence your bringing it up), which means you already understand what imperative is, and are still having to convert your immutable structure to a mutable one, for the imperative code to operate on, and to recognize it will be modified in place; to use the ST monad the functional programmer already has to understand imperative programming.

It also seems like it would fail to encapsulate the side effects an imperative function may have, since that function is able to interact with state elsewhere, that isn't actually encapsulated. I.e., the ST monad makes sense when dropping into update-in-place for performance reasons, but when there are side effects that are not ensconced within the monad (remember, the function you're calling was written by an imperative programmer, in a language that allows side effects outside of a monad; not Haskell), the ST monad does nothing to make it functional, and oh crap, now your functional programmer has the same problems as an imperative programmer, in having to figure out WTF this function just changed in some other imperative chunk of code, in some other process or object or whatever.

So given imperative and functional paradigms, even using the ST monad, if the functional code is to call the imperative, and the imperative is to call the functional, both the functional and the imperative developers have to understand the other paradigm, -and- deal with the considerations of both. You've upped the complexity of your system considerably.

Re:A farewell note to a programming language by tel on Thursday December 04, 2014 @03:08PM (#8701324)
It doesn't allow free crossing between an (imperative + mutable) world and a (value-centric + immutable) world, no. It, instead, allows for clear boundaries to be set between the two and each to be embedded into the other.

The ST monad also does exactly restrict the scale of effect of mutability which can occur. It's not a license for the imperative programmer to do whatever they want---it's a license for them to solve problems in the way they prefer within a particular ensconced region.

If you want, you can write a program where everything lives inside of a giant ST monad layer. You always do this if you replace ST with IO, in fact. Each bit which can be made purely functional will be embedded into this monad and, for sake of sanity and testing, those functional bits ought to grow and grow.

But it doesn't really demean the IO/ST segment. An imperative programmer can live happily there without much trouble at all.

Re:A farewell note to a programming language by lostcolony on Thursday December 04, 2014 @03:56PM (#8701574)
"It doesn't allow free crossing between an (imperative + mutable) world and a (value-centric + immutable) world, no. It, instead, allows for clear boundaries to be set between the two and each to be embedded into the other."

I wasn't saying you couldn't set boundaries; you have them implicitly simply by dint of the fact that in Scala, mutable/immutable is based on the type, and the type system is enough to enforce that. But now you have a performance penalty being introduced based on who works on a given part of the code, and one that can easily compound.

"It's not a license for the imperative programmer to do whatever they want---it's a license for them to solve problems in the way they prefer within a particular ensconced region."

But for the imperative programmer to know what not to do he/she has to understand functional coding, and choose to eschew certain techniques that might be viewed as acceptable from a purely imperative perspective.

Please note, I didn't say you -can't- do it. Just that it's asking for trouble, and that either you have to understand both paradigms or you suffer a performance penalty (converting from mutable to immutable and vice versa). And that if you ever want to touch someone else's code you have to be familiar with the paradigm. Not proficient, but enough to realize what you have to do to be able to interact with it properly/safely, that that requires a broader depth of knowledge on the part of each team member than if you picked one paradigm, and that leaving them to know only their paradigm will not work. The imperative person has to figure out higher order functions, working with immutable data structures, etc, to make use of some of the stuff the functional guy has written, and the functional guy has to be comfortable with destructive updates, side effects, etc, to be able to make use of what the imperative guy has written. Yes, they both can interface with the other, but what they have to know is much broader, and every time they interact you risk bugs and performance penalties that you'd not have if you picked one paradigm alone.

Re:A farewell note to a programming language by asdf1234 on Thursday December 04, 2014 @02:08PM (#8701005)
Pervasive use of ST, or almost any monad for that matter, leads to serious problems in Scala since you basically have to use trampolines and take a massive performance hit. It's also extremely verbose to do it correctly.

It's a good solution in Haskell though.

Re:A farewell note to a programming language by runT1ME on Thursday December 04, 2014 @02:27PM (#8701128)
This is FUD. You often don't need trampolines and there are better solutions than trampolines.
Re:A farewell note to a programming language by asdf1234 on Thursday December 04, 2014 @02:38PM (#8701180)
It's debatable whether abusing Free is a better solution. Either way, programming like this is disgusting in Scala and comes with tons of caveats compared to Haskell.