I don't believe the lack of semi-colons, which as mentioned earlier could be used if you prefer, was to appease anyone. It's simply an alternative syntax that many languages use today.

Good programming style includes not having multiple lines of code on the same actual line of the text file. I can't recall seeing a significant amount of code taking advantage of combining multiple-lines into one because the use of semi-colons allows it. The point is that good programming style makes the semi-colons moot and as one of the advantages of F# is its simplicity I think not using semi-colons is an excellent fit.

Strangely enough, although I started programming VB 17 years ago and

Python only about 5-6 years ago, my first inclination when seeing a

semi-colon/braces-free language is to compare it to Python not VB.
By on 3/10/2009 8:35 AM ()
Ending statements with semicolons isn't "normal." There are some language families that do it, sure, but there are more that don't. [insert some hard data here comparing a wide variety of languages - left as an exercise for the reader :-)]

And I wouldn't have chosen VB as an important ancestor of F#. To someone like me who's fairly new to the dotNet world, VB seems like an evolutionary branch that hasn't influenced much of anything. I'm not a hardcore language geek, so I could easily be wrong, but it's not like you read about language design and see lots of statments like "we took this idea from Visual Basic."
By on 3/10/2009 11:08 AM ()
Why can't F# use semicolons to end statements?

With the exception of for-loops, the overwhelming majority of semicolons in C/C++/C#/Java is exactly:

;/cr/lf

Further, the semicolon syntax is much _less_ precise. Consider the canonical example:

x = x++;

Is x equal x or x++?

All the useful (for me at least) cases of semicolon can be be done in f# in a cleaner way.

Also, as far as I know, you can use ;; to terminate any statement (if you want to). But, it's redundant, so #light makes it optional.
By on 3/10/2009 7:28 AM ()
I have to admit that I've said I like F# by only giving the language a cursory examination. I'm now working through a book on F# with the purpose of mastering the syntax of this language, and I have to say I still like the more precision syntactic nature of C/C++ or even C# a lot more.

Why can't F# use semicolons to end statements? F# uses a CR/LF pair to end statements and I can see that the language still needs semicolons to define types, lists, etc. Why use CR/LF to end statements at all, if you have to use semicolons in the language in other contexts? Was this perhaps to appease those lame VB developers? That sucks.

I'll pesevere with my pursuit of mastery over this language because I know that parallel programming is the future and F# makes that easy.

Thanks.

I'm not so sure I understand. Why is terminating a statement with a semicolon more "syntactically precise" than using indentation to denote the beginning of a new statement? I'm also not sure I understand what you mean by "Why use CR/LF to end statements at all, if you have to use semicolons in the language in other contexts". Semicolons are just one character out of thousands of possible unicode characters. I could change your statement to say "Why use CR/LF to end statements at all, if you have to use ampersands (&) in other contexts." I don't see the connection. C / C++'s choice of using semicolons to terminate statements was an arbitrary choice on their part when they designed it, it doesn't mean it's the canonical programming methodology of terminating statements that all real world programming languages should use lest they be considered impractical for real world problems.

There are lots of other functional programming languages, and almost none of them use semicolons to terminate statements. Enforced indentation has some negatives, but it has plenty of positives too. It's not right or wrong, it's just the way it is. /shrug
By on 3/9/2009 6:32 PM ()
Well, the reason I picked the semicolon character while stating that F# could've used it to end statements is that I can see that F# has elements of C/C++ in it, like printf and the underscore embedded in certain keywords (or library functions, or whatever). And C/C++ use semicolons to end statements, which is certainly a more precise syntax than some whitespace. How would some long statements look on a text editor like notepad, or if such F# code is printed on paper? Lots of people still use printed books to learn, and using whitespace to end statements introduce ambiguity into code displayed in such medium.

I won't bother to categorically respond to every other post that's been posted in response to mine, but if you're a C/C++/C# or even a Java developer, you would understand why semicolons can be helpful.

And for that reason, I hate F#'s way of declaring identifiers without attaching proper types to them - there's more ambiguity right there. But I can see that there's a way around that, and that's what I'll use. I've noticed other such problems in the language elsewhere, but I can't be bothered to spell all that out here.

P.S. I know a lot of people that think the Heavy Metal music genre is about a lot of pointless and screaming vocals. If you listen carefully, and gave Metal half a chance, you'll see that those vocalists actually hit a lot of notes while doing all that screaming. Unlike pop music vocalists that sing softly, Metal vocalists have to sing at the top of their voice to be heard above those distorted guitars, and when your voice is stretched that way, its very difficult to hit notes. It takes a lot of practice.

P.P.S. I'm ending my posts to this thread here.

By on 3/10/2009 1:03 PM ()
I guess most people around here are C/C++/C# or Java developers but we are mature enough to know that not every language has to look like C.

And guess what: F# follows a heritage from OCaML, ML, ... straight to LISP and LISP is actually older than C - OK you don't have so many ";" in LISP but you get a lot '(' and ')' ;)

So what? Complain why C uses the ugly "{" instead of the historical "(" ?

Why even complain about some meaningless stuff like the presence or absence of a terminal symbol like ';' when we should discuss things like the demand of the comunity for actual type classes in F# ;)

Just give F# and FP a chance (just like you gave one to HM :P ) - I don't think you will be disappointed as soon as you actually understood the languague and functional programming.
By on 3/10/2009 10:49 PM ()
FSEnthusiast, F# syntax is very flexible. You can end statements with a semi-colon, or a a end of line, or both. But usually, we try to avoid side effects, and we don't use statements.

You're allowed to specify type informations (almost) anywhere you want, or you can let the compiler guess them. It's up to you.

Light syntax, where spaces are significant, seems to be more inspired from Python (although, Python's one is quite poor) and Haskell, than from VB. Semi-colons were introduced in C for parsing reasons: it was for the compiler, and not really for the programmer. To me they are quite noisy, they are useful only when two statements are on the same line.

Banshee, most languages allow semi-colons for sequences of instructions. Look at this page (it's very interesting, even if some F# information is a bit outdated now): [link:rigaux.org]

Laurent.
By on 3/10/2009 4:55 PM ()
It's natural to have a separator such as semi-colons in imperative languages, such as C and its offspring. Programs in these languages are sequences of operations which must be executed in exactly the order in which they are written. Programs are essentially lists of operations, and I personally think that semi-colons make good separators in lists.

Functional languages inherit from the mathematical notation, which is based on formulas and expressions. The order in which parts of an expression is evaluated is not so important. Actually, some parts may not even be evaluated at all! Functional programs have less of a linear structure, more tree-like. In this context, operators play the role of separator, and there is no single symbol that will fit all situations.

Now, you may point out that C supports expressions, and F# supports imperative constructs, so both have operators and separators, but they still have different origins, which is reflected by their syntax.

My background is also in C++ programming, F# is my first functional language. I was also a bit repelled by the syntax at first, but I no longer mind. I'm really starting to appreciate its conciseness, actually. After you have learned more about F# you may see why the semi-colon no longer occupies the center of the stage in F#. For instance, you may notice that |> starts appearing a lot in your code, somewhat replacing ;

By on 3/10/2009 3:34 PM ()
Well, the reason I picked the semicolon character while stating that F# could've used it to end statements is that I can see that F# has elements of C/C++ in it, like printf and the underscore embedded in certain keywords (or library functions, or whatever). And C/C++ use semicolons to end statements, which is certainly a more precise syntax than some whitespace. How would some long statements look on a text editor like notepad, or if such F# code is printed on paper?

It would be even more immediately obvious that the statement has ended in F# than in C++, because in F# as soon as the indentation shifts to the left, the statement is over. You don't even have to examine the code, it just jumps out at you. Which of the following, for example, is easier to find the statement breaks in?

   int result=4; ++result; int r2 = 0;  if (result < 7) r2=4 else (r2 = (int)System.Math.Sqrt(result*result*2));  System.Console.WriteLine("Result is {0}!", r2);

   let result = 4
   let r2 = 
       let plus_one = result+1
       if (plus_one < 7) then 4
       else System.Math.Sqrt(plus_one*plus_one*2)
   printfn "Result is %d" r2



You might say it's bad programming practice to do the first in C++, which it definitely is, but it's possible, whereas in F# it's not even legal to do something like that. Furthermore, you can figure out where every single statement ends trivially, by just looking at all lines that have the same indentation level.

Lots of people still use printed books to learn, and using whitespace to end statements introduce ambiguity into code displayed in such medium.



I categorically disagree. In fact, I would argue the exact opposite. When you read messages from someone who never uses paragraphs, it's extremely difficult to read. It's so difficult to read that it even has its own name (wall-o-text). As soon as you introduce a few paragraph breaks, it becomes extremely easy to read. You dont' even have to search for where the paragraph ends, because glancing at the page for about 10 milliseconds would see that it's exactly where the big empty line is.

if you're a C/C++/C# or even a Java developer, you would understand why semicolons can be helpful.


I've been a C++ developer for 12 years :-/ Aside from C#, which I don't even consider since it's so easy for a C++ programmer, F# is the first language I have put any serious amount of effort into learning.


And for that reason, I hate F#'s way of declaring identifiers without attaching proper types to them - there's more ambiguity right there. But I can see that there's a way around that, and that's what I'll use. I've noticed other such problems in the language elsewhere, but I can't be bothered to spell all that out here.
Honestly I think you're just missing the entire point of F#. There's no ambiguity whatsoever in not attaching proper types to variable identifiers. Literally, none. F# is more strongly typed than C++, Java, and C#. The difference is that in a language like C++, you have to actively think about when to make a function into a template function. There are plenty of people who have written this function in C++

int max(int a, int b) {   (a>b) ? a : b;   }

when it would have been better if they had used a template. That's a trivial example, but it applies for just about anything. F# automatically "templatizes" everything that it is technically possible to templatize, and it does so while still remaining more type safe than C++.

Also, for the record, I really like some heavy metal music :P
By on 3/10/2009 2:31 PM ()
Well, one thing is for sure. F#'s certainly getting a broader audience.
By on 3/10/2009 1:20 PM ()
Well, one thing is for sure. F#'s certainly getting a broader audience.

I wouldn't be so sure. I seem to recall that VB passed COBOL for most LOC in production (I can't find a source, so take that for what it's worth). Anyway, VB certainly has a huge following, and VB.NET is basically C# with ugly syntax.

In defense of the OP, non-Algol syntax can be shocking until you get used to it, and some, otherwise extremely competent, people never quite ``get'' functional languages.

I think if the only whitespace-significant language that I used was VB, I would probably be turned off by it. Similarly, a lot of people are turned off of functional programming because they don't like the parens in LISP.

It sounds like the OP is giving a real effort to f#. So, I think it will pay off when he starts to wonder how he ever did _anything_ in a language without first-class functions. (and the indenting is just as much second nature as semicolon-brace.)

[edit]Who knew that Algol68 supported first-class functions? [link:en.wikipedia.org][/edit]
By on 3/10/2009 2:06 PM ()
Could you explain "more precision syntactic nature of C/C++ or even C# a lot more"? Is there code you're writing in F# that ends up with ambiguous syntax? Or I'm just not understanding :\.

I don't see where VB factors into it. I thought that Haskell and Python influenced the whitespacing system. Last I checked, VB didn't have significant whitespace apart from crlf...

Glad to hear you're going to continue studying it.
By on 3/9/2009 4:41 PM ()

I have to admit that I'm baffled by this request. I've always found unnecessary curly braces, superfluous semicolons, explicit type definitions and other redundant syntax very visually noisy - stopping me from quickly understanding the essence of the algorithm.

let f x = x * x

expresses the essence, whereas

namespace MyNamespace
{
   public static class MyClass
   {
      public static int f (int x)
      {
         return x * x;
      }
   }
}

is concerned mainly with the ceremony. This difference becomes dramatic when dealing with higher-order functions.

Glad to hear #light is becoming the default.

regards,

Danny
By on 3/9/2009 5:42 PM ()
You are welcome to use semicolons at the end of your statements, but they are optional in #light mode (soon to be the default). You don't need semicolons to define types. Semicolons are used for delimiting elements in a list, but newlines work there too. I often write hundred of lines of F# without a single semicolon. The language is pretty syntactically-forgiving when it comes to demiliting/terminating various entities -- do something reasonable, and it probably just works!
By on 3/9/2009 3:58 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us
Built with WebSharper