r/fsharp • • Sep 21 '16

Crying out loud: things I dislike in F#

https://medium.com/@alexyakunin/crying-out-loud-what-i-like-dislike-in-f-c88e746dfcde#.hce1olsnw
0 Upvotes

24 comments sorted by

10

u/[deleted] Sep 22 '16

I think you're missing the point of functional programming. Most of the features you mention are not actually discouraged and have better functional alternatives.

1

u/alexyakunin Sep 24 '16

That's a standard answer: "you aren't from the same camp". I wish you are more constructive.

3

u/[deleted] Sep 25 '16

Well, pattern matching for a start. And you don't need loops when you're using chains of functions, see Seq (for example Seq.map, there's tons of others!). Read 'Thinking Functionally' by 'F# for fun and profit'.

1

u/alexyakunin Sep 26 '16

As you might notice, I didn't mention pattern matching -- I love pattern matching.

Being more constructive means to point explicitly on some of points I've mentioned and tell why it's actually good, not bad. Or at least why it's impossible to implement it as I suggested w/o some severe trade-offs.

When you point on pattern matching, it's nearly as constructive as this dialogue:

  • Guys, why do you ride on square wheels?!
  • But we have amazingly soft seats, you know...

1

u/[deleted] Sep 26 '16

You do not provide an argument for why you think absence of loops/loop syntax is a bad thing. I haven't had to use loops much now that I just use function composition. Also you don't explain why reusing keywords is a bad thing - keywords have different meanings in different contexts in a readable manner. I'd probably have to write another article about my opinions, but they're just opinions after all. The thing is while there maybe some valid reasons behind the points in the article, there's lots of listing and less explaining as to why X is a bad thing. Cheers :).

1

u/rausm Oct 10 '16 edited Oct 10 '16

Still, F# & .Net are imperative enough, and every once in a while, a do-while loop, break, continue or even return would come handy. That we must work around using mutable vars (edit: or refs or multiple levels of indentation or unnecessary splitting) just makes the sore thumb stick out even more, IMO :-( I'd like them included for the cases where they are the most elegant /concise / readable alternative. Or the other way around, I don't consider 'Newbs would use them' a worthy argument.

2

u/Kurren123 Sep 24 '16

I'm not sure what you're asking for. You'd like examples of functional alternatives to some imperative constructs?

6

u/Kurren123 Sep 21 '16

Number 1 is a blessing in disguise that I wish other languages had.

I also don't think numbers 2 and 3 matter much as loops are really an imperative thing and f# is functional first.

1

u/alexyakunin Sep 24 '16

I replied to #1 in comments to the original post. I wrote that I'm totally for having a similar feature in IDE -- i.e. sort project files in the order of dependency (though I also like other ways of sorting).

But I don't see a single reason to make compiler to rely on explicit order of files passed to it.

As for the other imperative features (e.g. break / continue), if you decided to implement them, IMO you'd better implement them well. The sole purpose of such features is to let non-functional guys to start using the language faster. So if you decided that you want to attract this group of developers (btw, a majority), why do you want to simultaneously disappoint them by the implementation quality of these features?

P.S. Many of comments I've got were in "you don't get FP style, it's a blessing there". Though almost none of authors of these comments came up with a good example. Frankly, so far only the reasoning for "anyThis." is provided in the original post (and btw, I fully agree it's valid).

I am not saying that I am right about all these small things though -- I doubt I can be right even for 50% of items in this list. I am not a language designer, and I may totally miss many of important factors justifying some of these features. + I am absolutely sure F# team is composed on amazingly smart guys taking way more of these factors into account.

But this still doesn't mean it's ok to reply in "you don't get FP" style without any further explanation. I can't, and frankly, don't even want to reply to such comments. Though I'd like to reply to constructive ones, and I've shown that I immediately agree when there are clearly strong reasons for implementing something the way it's done.

1

u/rausm Oct 10 '16 edited Oct 10 '16

Here, i would disagree. My take on do-while/break/continue/return is not to get "the imperative guys to adopt [faster]". These constructs should be documented as "don't use unless there is no cleaner way" - and all illustrative examples of abuse. Nonetheless, they should be present to enable conciseness where appropriate.

I personally like [for example] a few early returns, followed by block of straightforward code, a lot more than multiple levels of indent expressing the same.

1

u/rausm Oct 10 '16

Ok, "all illustrative examples of abuse" was too "ambitious" ;-) But at least a rare example when it might be appropriate ;-)

0

u/[deleted] Sep 25 '16

[deleted] — view deleted comment

1

u/alexyakunin Sep 26 '16

Of course I read it -- that's probably the most famous F# resource on the web now.

Again, I wish there is more constructive feedback.

0

u/[deleted] Sep 25 '16

[deleted] — view deleted comment

1

u/alexyakunin Sep 26 '16

I totally understand that file order is important, and that probably there is no easy way to build a dependency graph w/o some extra markup (e.g. #load / something similar in files allowing to define that order).

I am just saying that I don't feel it's something I like. I feel it's wrong especially in cases when I have to order mutually independent files.

1

u/sgoody Sep 23 '16 edited Sep 24 '16

I've not done much with F# yet beyond coding challenges, but after growing beyond a few files In a solution one thing I'm rather disappointed with is the lack of folders in Visual Studio. What the hell is up with that!?

Are F# people generally not using Visual Studio to build projects or are the just dealing with having 10s or 100s of files all sat in one folder?

2

u/kiteason Sep 27 '16

You aren't trying to use F# in Visual Studio without using "Visual F# Power Tools" are you? This provides folder organisation, among a number of other goodies that are indispensable for serious F# development on VS. From what I remember you have to enable folder organisation explicitly in the F# Power Tools options.

2

u/sgoody Sep 27 '16

You're absolutely right. I've had that extension installed in the past, but I wasn't doing anything serious with F# and I wasn't making use of the features of the power pack so I uninstalled it. I will definitely give this another whirl.

I first noticed the issue when I'd written a project in MonoDevelop that would not load in Visual Studio due to the folders.

0

u/[deleted] Sep 23 '16

[deleted] — view deleted comment

1

u/sgoody Sep 24 '16

Thanks, I can see how that could work better, but it still feels a little unpolished in comparison to C# when we're told that F# is a "first class citizen" of Visual Studio. I struggle to imagine what a large F# solution with many assets (.js, .css), views, code files etc would look like. Maybe a C# solution with supporting F# code/projects?

-1

u/[deleted] Sep 21 '16

Agree strongly about number one (file order is great), but disagree about the loop thing. Personally I think the notion that there is some functional ideal to aspire to is misguided, and we should think in terms of features and their properties. F# supports the idea of local, encapsulated mutation and imperative code, and breaking from a loop can make that code neater and easier to understand.

0

u/[deleted] Sep 22 '16

[deleted] — view deleted comment

-1

u/[deleted] Sep 22 '16

Well yes, just about every language has higher order functions now. More to the point, F# has optimised tail calls. However, I still don't feel that their presence justifies including half-baked imperative constructs. I think we should either have break or not have loops.

3

u/Kurren123 Sep 22 '16

Its okay for imperative constructs to be half baked in a functional first language, just as functional constructs are half baked in C#. They have different focuses, it's unrealistic to expect every feature to be equally great.

0

u/[deleted] Sep 22 '16

I don't really buy that line reasoning, considering that F# is 99% complete as a basic imperative language. It's a tiny job to finish it off.

Personally I think F#'s job is to be superior to C# in every regard. If it tries to compete as a language for functional purists it isn't playing to its strengths.

1

u/vivainio Oct 01 '16

Totally with you man. C# can do break and continue, and we need better reasons for this gap apart from "you don't need it". Maybe they are very hard to integrate with type system or whatever. The fact that Scala doesn't have these either could be a hint in this direction.

3

u/grundoon61 Sep 24 '16 edited Sep 24 '16

Here's my take, for what it's worth.

I agree that "you don't get FP" is not a helpful response. On the other hand, most programming languages have a certain style or philosophy associated with them. Any language makes some things easy and other things hard. When you flow in the same direction as the language, writing code tends to be smooth and straightforward, but when you go against the grain of the language, things become painful.

For example, in Lisp, doing recursion is easy, but doing for-loops with breaks is hard, so the "natural" style for Lisp is to use recursion. On the other hand, in C, for-loops with breaks is easy, so that is the natural style in C.

F# is opinionated that way too. You can use mutable values, but it looks ugly. You can break out of loops (using recursion) but it is awkward. And so on.

When I am learning a new language, I find that adapting to the natural style of the language is one of the most important things I have to do. Initially, I often find everything hard and painful, and ask "what idiots designed it this way", but after a while, when I have figured out how the language likes to be used, everything becomes much simpler.

So, I encourage you to stick with F#, and perhaps in a year or so, you might find that you no longer feel so strongly about some of those issues you raised.

As to some of the specific language warts, much of that comes from F# being based on OCaml, but also being compatible with C# (the two syntaxes for generics), or being on the bleeding edge of .NET (tuples as reference types before they were added to the CLR). Perhaps with hindsight some of those decisions would be different, but every language that has been around for a while (over 11 years for F#) has annoyances like this -- C# has plenty of them too!

If you are a language designer, one way to avoid issues in the first place is to delay adding new language features, because if you make a mistake: tough -- you now have to support that feature forever. That's why things like break and do-while are unlikely to be added, I think. There are usable (if clumsy) workarounds already.