[RFC FS-1110 Discussion] Allow expr[idx] for index/slicing #611
Replies: 28 comments 28 replies
-
I personally don't think it will make that much of a difference, coming from C# it doesn't really trip me up or is big enough to create barrier. I've not even had anyone bat an eyelid at the difference. Once you accept the difference between WRT porting code, I think that F# is enough of a different syntax that you wouldn't gain much, a simple replace regex could help turn |
Beta Was this translation helpful? Give feedback.
-
I'm sure python programmers would appreciate one -- and preferably only one -- obvious way of doing this. |
Beta Was this translation helpful? Give feedback.
-
There is no reason to do this. Python does nothing to accommodate F# programmers, so I don't see any need for F# to extend such a courtesy to Python programmers. I cannot imagine that the addition of this method of indexing is going to convert even a single Python programmer to F#. |
Beta Was this translation helpful? Give feedback.
-
Feedback from Niklas at Microsoft |
Beta Was this translation helpful? Give feedback.
-
Hugely in favor of doing this and more than happy to delete the code fixer in VS tooling for it. I think the thing that sucks the most about the current experience is that there's no way in tools to know that after you typed the |
Beta Was this translation helpful? Give feedback.
-
I think this under-estimate the importance of syntax differences in the minds of people. When you compare machine learning code in Python with F#, this absolutely stands out. Likewise code from C#/Julia/Java/C++. Two of the most experienced researcher/architect/programmers I know have repeatedly asked me about this specific point. Again. And Again. And Again. They don't let go. |
Beta Was this translation helpful? Give feedback.
-
The Having said all that I think requiring the space to disambiguate between an argument and an indexer is pretty clear and I do think it would remove a bit of friction when first learning the language. |
Beta Was this translation helpful? Give feedback.
-
Oh god yes, please. Please, yes. i am ecstatic just thinking about it - great early Xmas present |
Beta Was this translation helpful? Give feedback.
-
I’m in favor. |
Beta Was this translation helpful? Give feedback.
-
Please do it - I always assumed there were technical reasons for the dot being there. It's just an unnecessary mental hurdle for someone keen to write their first code. You get over it, but it's friction and you can better use the learning curve time on something that's a genuine language difference. |
Beta Was this translation helpful? Give feedback.
-
I kind of like the Scala way, where function application and array lookup have the same syntax. I guess that would be more difficult to do for F# due to type inference, so probably not an option. Imho, |
Beta Was this translation helpful? Give feedback.
-
Pros:
Cons:
|
Beta Was this translation helpful? Give feedback.
-
I don't think of this as accommodating Python or attracting its users. I just want beautiful code. .[] is a wart, IMO. Indexing looks like expr[idx] or expr(idx) in every single other language I can think of. So, in my mind, it's just about aesthetics, simply, and aesthetics matter. I don't think anyone will be persuaded to use F# because of this, but if every time I have to say expr.[idx] I find myself grimacing, then over time I will think less of the language than I would otherwise. This plus support for implicit conversion operators will make F# a far better language for numeric code. Aesthetically, that is. Functionally, it already is great. |
Beta Was this translation helpful? Give feedback.
-
I constantly switch between different programming languages and the F# indexer syntax has never bothered me. |
Beta Was this translation helpful? Give feedback.
-
This is a really great idea! 😍 F# can be harder for experienced programmers (needing to unlearn this muscle reflex). There should imo be a very good reason for the |
Beta Was this translation helpful? Give feedback.
-
This is great. I think doing in two ways in the same file is also fine. It is good to be flexible and reduce the unnecassary gap between languages and devs. |
Beta Was this translation helpful? Give feedback.
-
Great idea! This might be one of the initial steps to increase the conversion rate from Python-based Machine Learning/Data Science/Deep Learning to F#/.NET-based :-)
|
Beta Was this translation helpful? Give feedback.
-
I'm against this. It feels like an unnecessary syntactic sugar over 1 character. Like implicit yield was a feature that could save up lots of characters not to mention nice look and feel. But this is simply something that new programmers have to learn. Honestly it's just a dot. |
Beta Was this translation helpful? Give feedback.
-
I totally support this small sacrifice to make language more attractive for newcomers. |
Beta Was this translation helpful? Give feedback.
-
I would like very much the change (not having the dot), main reason less noise. I see this change as good thing for the F#, not as a tool to attract other developers that know other languages. |
Beta Was this translation helpful? Give feedback.
-
F# is my main language, say 80%. When I come back from js, ts, c# or else and quickly write an f# script I often forget the .[] . No big deal, but the proposed change here aligns syntaxes across languages which I find practical and also a nice and open attitude of language design. Yes, pleeease. |
Beta Was this translation helpful? Give feedback.
-
I like the efforts to bring F# closer to widely accepted code conventions to ease onboarding of newcomers. However, I'm more stumbled upon two other syntaxes than In F#, Another one is My point is that unfortunately we will never get there to please coders from different background completely. But I hope every bit of effort helps. |
Beta Was this translation helpful? Give feedback.
-
While I appreciate the efforts in getting F# to more closely match other languages, what does this mean for calling functions and passing lists as arguments? TBH I see two possibilities and neither of them are great: (1) let x = dict ([1, "one"; 2, "two"]) // Parens are now required (2) let x = f [1] // This is calling a function, passing in a list
let y = g[1] // This is indexing I think the difference between the two syntaxes in (2) is too small, so I wouldn't go for that (I also don't believe there are any other places in F# where a single space like that would change the syntax of an expression) but then having to add brackets to function calls as in (1) would really suck. Not sure I like this |
Beta Was this translation helpful? Give feedback.
-
Great idea. One less trip hazard for new users, and rewards those who use their intuition (based on other languages, granted) to figure out indexing syntax. |
Beta Was this translation helpful? Give feedback.
-
I don't think this is a good idea, for a few reasons:
TL;DR- I don't believe the stated motivation justifies such a disruptive change. However, I'd support the addition of the Alternatively, to make the current syntax more discoverable, we could simply add some helpful text to the error shown when |
Beta Was this translation helpful? Give feedback.
-
I think this would be great, especially for new programmers, who are just learning F#. |
Beta Was this translation helpful? Give feedback.
-
I'm all for this provided that there is no loss of functionality. I use many overloads for index/slicing in Flips which you can see here. This would ease the migration of people writing Mathematical Planning models from Python to Flips. The MP domain uses index/slicing heavily. |
Beta Was this translation helpful? Give feedback.
-
As someone said, this is a wart. I read that statement as intentionally ambiguous: do I mean that Every time I show F# code to machine learning/computer vision folks, I find myself saying "yes, It's not a case of pandering to pythonistas, or mollifying matlabbers, or soothing C/C#ers -- the F# programmers I care about are not those who use it today, but the many many more people (we hope) who use it in the future. We should welcome those new joiners, and until everyone's first language is F#, we should meet their expectations where we can. |
Beta Was this translation helpful? Give feedback.
-
Discussion thread for https://github.com/fsharp/fslang-design/blob/main/preview/FS-1110-index-syntax.md
Beta Was this translation helpful? Give feedback.
All reactions