Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tabs in identifiers #797

Open
Happypig375 opened this issue Oct 21, 2019 · 5 comments

Comments

@Happypig375
Copy link
Contributor

@Happypig375 Happypig375 commented Oct 21, 2019

Tabs in identifiers

I propose we allow tabs in identifiers. This can be used to make identifiers that are directly copied from Excel files. (Copying from multiple cells produce tabs.)

Microsoft (R) F# Interactive version 10.6.0.0 for F# 4.7
Copyright (c) Microsoft Corporation. All Rights Reserved.

For help type #help;;

> let ``	`` = 3;;

  let ``	`` = 3;;
  ----^

stdin(1,5): error FS0010: Unexpected reserved keyword in binding


  let ``	`` = 3;;
  ------^

stdin(1,7): error FS1161: TABs are not allowed in F# code unless the #indent "off" option is used


  let ``	`` = 3;;
  ------^

stdin(1,7): error FS0010: Unexpected reserved keyword in interaction

> > 

The existing way of approaching this problem in F# is having to replace tabs with spaces.

Pros and Cons

The advantages of making this adjustment to F# are

  1. Consistency - All non-newline Unicode characters are allowed as identifiers. Why not tabs specifically?
> let ``�`` = 4;; // U+FFFF
val � : int = 4

> let ``�`` = 4;; // U+0000
val � : int = 4

> let ``�`` = 4;; // U+0008
val � : int = 4
  1. Convenience - I should be able to directly copy-paste from an Excel file to F# code as an identifier.

The disadvantage of making this adjustment to F# is a more complicated checker for tabs in the compiler.

Extra information

Estimated cost (XS, S, M, L, XL, XXL): S

Related suggestions: (put links to related suggestions here)

Affidavit (please submit!)

Please tick this by placing a cross in the box:

  • This is not a question (e.g. like one you might ask on stackoverflow) and I have searched stackoverflow for discussions of this issue
  • I have searched both open and closed suggestions on this site and believe this is not a duplicate
  • This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it.

Please tick all that apply:

  • This is not a breaking change to the F# language design
  • I or my company would be willing to help implement and/or test this
@abelbraaksma

This comment has been minimized.

Copy link

@abelbraaksma abelbraaksma commented Oct 21, 2019

Many editors convert tabs to spaces, and even if your editor doesn't, your colleagues could end up with errors because they get converted.

Conversely, if you really must copy and paste from Excell (I don't see why that should be a requirement, the same argument could be used for any other program out there), if you do convert tabs to spaces, you would already have fixed it.

But honestly, consecutive blanks, and tabs specifically, are notoriously hard to read (you cannot distinguish a single space from a tab that indents one), unless you have visible spaces switched on. I'd argue you're better off with the current stricter rule.

Btw, nothing stops you from writing a relatively simple add in that hooks on the paste action, which is perhaps a better way to tackle issues related to importing stuff from external applications.

@yatli

This comment has been minimized.

Copy link

@yatli yatli commented Oct 21, 2019

tabs are variable length and this are not human-readable identifiers.

@Happypig375

This comment has been minimized.

Copy link
Contributor Author

@Happypig375 Happypig375 commented Oct 21, 2019

Invalid Unicode characters can already be identifiers. What makes tabs special?

@yatli

This comment has been minimized.

Copy link

@yatli yatli commented Oct 21, 2019

Tabs are contextual, meaning that it changes shape according to its position.

Assume tab stop=8:

let ``	a`` = 1
let b =
         ``	a``
// they look different to a human but means the same thing, so how can we use them as identifiers?

I'm not sure what 'invalid unicode characters' you're referring to, example?
I think most are regarded as fixed-length (narrow, or wide)
In your example, all those characters (U+0000, U+FFFF, U+0008) are valid code points in the BMP, and are not even ambiguous length.

@abelbraaksma

This comment has been minimized.

Copy link

@abelbraaksma abelbraaksma commented Oct 21, 2019

In your example you did not use invalid Unicode characters. The editor replaced the invalid Unicode character with the Replacement Character, see https://en.m.wikipedia.org/wiki/Specials_(Unicode_block)#Replacement_character, which is valid (if you doubt this, check your saved file with a hex editor and check the UTF-8 encodings).

As for why they are special, I tried to summarize that in my first comment. We can disagree on the usefulness but the tab vs spaces discussion was decided in the early days of F# in favor of spaces and I doubt they would make an exception. Even more so because it would create code that looks different in different editors.

Just (auto) replace them with spaces and you should be fine. This post, while for C#, shows some ideas how to use EditorConfig extensions, perhaps you can have it apply to F# just as well: https://www.hanselman.com/blog/TabsVsSpacesAPeacefulResolutionWithEditorConfigInVisualStudioPlusNETExtensions.aspx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.