11 ms·
One thing I find annoying about Nim is the case insensitivity [0]. There was no strong reason for this "feature" and literally no mainstream language does it. M
by nphard85 7y ago
One thing I find annoying about Nim is the case insensitivity [0]. There was no strong reason for this "feature" and literally no mainstream language does it. Moreover it makes code search a pain.
[0] https://nim-lang.org/docs/manual.html#lexical-analysis-identifier-equality https://nim-lang.org/docs/manual.html#lexical-analysis-ident...
- creatornator 7y agoYou can use nimgrep [0] to find symbols that match each other with case insensitivity, but yeah it is unusual. [0] https://nim-lang.org/docs/nimgrep.html https://nim-lang.org/docs/nimgrep.html
- nphard85 7y agonimgrep's alright. I was thinking of code search on, say, github. I feel the additional complexity was unnecessary in an otherwise well designed language.
- lazulicurio 7y agoVB.net is case-insensitive, and probably more popular than you think[1]. I think that case insensitivity actually does make sense when working with symbolic identifiers. I've seen justifications for "Foo" and "foo" being distinct symbols; personally, I find that playing with casing like that reduces my ability to read code quickly. Case insensitivity does have its downsides, but usually it's not as noticeable in VB.net because most development is done in VS, which automatically re-cases symbols to match the original definition. [1] Number 6 based on search engine popularity according to https://www.tiobe.com/tiobe-index/ https://www.tiobe.com/tiobe-index/ Also, anecdotally, it's used quite a bit in industrial automation.
- cwyers 7y agoSQL also does it (albeit inconsistently).
- nine_k 7y agoWith a tool which removes case inconsistency, it's almost like a language which is case-sensitive.
- lazulicurio 7y agoAlmost, but not exactly. For example, you still can't have multiple symbols in the same scope that vary only by case. Which, personally, I'm okay with.
- ac29 7y agoAs an admittedly amateur programmer, I think the reasoning is solid. Its difficult to read and understand code that does things like myvalue = myValue. I think they made the right tradeoff, in that value != Value (the case of the first letter is used), so if you really need to have to values with the same name, you can still do it. As an aside, is there some reason that using the same identifier with different cases is desirable?
- SamReidHughes 7y agoIn many languages, you might use one for a type name, the other for a variable. You could ban using the same identifier with different cases, instead of treating them the same.
- blueprint 7y agoOn the other hand, what if it's a code UI limitation? Suppose the UI for writing Nim had support for linking, editing, viewing all such alternately spelled but equivalent symbols?
- SamReidHughes 7y agoThere are tools that aren't nim-specific, like ack/grep/sed/git, and code review tools, which suffer as a result.
- coldtea 7y agoThen it limits me as a programmer to have to use said UI...
- narimiran 7y ago> In many languages, you might use one for a type name, the other for a variable. And Nim is one of those languages too. This is perfectly valid and frequently used: type Person = object name: string age: int let person = Person(name: "you", age: 99) echo person You can try it in Nim Playground: https://play.nim-lang.org/#ix=20jS https://play.nim-lang.org/#ix=20jS
- ken 7y agoSQL, BASIC, HTML.
- ryl00 7y agoFortran and Ada, as well.
- Stratoscope 7y agoIt's not just case insensitive, it's underscore insensitive. So MyNimName, mynimname, MY_NIM_NAME, My_Nim_Name, __MYNIM___name_, and any other variation you can think of are all the same name! Most search tools have the option of case sensitive or insensitive search, but a search that does that and ignores underscores? Not too many of those outside the Nim world. An interesting contrast is Nim's policy on tabs and spaces for indentation. Spaces are fine. You can use as many as you want. Two, four, three, whatever. Nim doesn't care. But Tabs? They are forbidden! Unless you use this magic line at the top of each source file: #? replace(sub = "\t", by = " ") Now you get to use tabs!
- kungtotte 7y agoNim is actually case sensitive on the first character only, so your list of identifiers are not all equivalent. Just thought I'd point that out for correctness sake.
- Stratoscope 7y agoOh, thank you for the correction, and sorry for the misinformation! In any case (pun intended?) it's the underscore insensitivity that makes it difficult to use standard search tools.
- PMunch 7y agoAgain just for correctness your last identifier isn't legal in Nim. You aren't allowed to start an identifier with an underscore, and you can't have two underscores together.
- atilaneves 7y ago> it's the underscore insensitivity that makes it difficult to use standard search tools. I personally don't like the feature, but what do you find difficult about using /my_?[vV]ariable/ to search for any of myvariable, my_variable or myVariable?
- Seb-C 7y ago
- swalladge 7y agoThis. I like many of the things that Nim is doing, but I refuse to take it seriously if it's going to make basic things like tag search and grepping difficult. inb4 a Nim linter is written to force a consistent naming style throughout a codebase.
- alpaca128 7y ago> inb4 a Nim linter is written to force a consistent naming style throughout a codebase. Already done: https://github.com/FedericoCeratto/nimfmt https://github.com/FedericoCeratto/nimfmt > Detect inconsistent variable/function naming
- swalladge 7y agoHA well there you go. This shouldn't have to exist.
- SolitudeSF 7y agoyou can compile with `--stylecheck:error/hint` for enforcing consistent naming.
- 0xfffafaCrash 7y agoDisallowing these case/underscore variants from referring to differing values could be quite ok -- even a plus-- if (but only if) an additional rule is added to disallow any variations of the declaration-time casing for a variable within the same scope to prevent the need for bespoke grepping tools and discourage arbitrary variations. If that restriction was added one could argue that this improves code readability (& "listenability") by have fewer variable names available in the same scope which would sound the same but aren't.
- adrusi 7y agoEven with such a rule, you would still run into problems if you want to grep for a token that's used in some application but declared in a separate library.
- emmanueloga_ 7y agoAnother precedent for case weirdness :-) https://stackoverflow.com/questions/7375537/why-is-common-lisp-case-insensitive https://stackoverflow.com/questions/7375537/why-is-common-li...
- coldtea 7y agoEvery good language must have some batshit crazy bizarro wart thrown in...
- honewatson 7y agoI've been using Linux since the late 90s and case sensitivity has never been an issue for me with Nim since I started using it in 2016. This is FUD and fake news.
- treeform 7y agoMain reason for this feature is that Nim is big as a glue language. Many C/C++ libraries don't have consistent naming conventions between them. I don't want my code to look like a patch work of `__APICALL__(system_call.inspectSomething())` I just want it to look like Nim code: `apiCall(systemCall.inspectSomething())`. This is just a consistent standard on how to turn names in one style into another style backed into a language.
- airstrike 7y agoapiCall = __APICALL__ done
- treeform 7y agoThen you are writing or auto generating these giant 1000s of lines long files with renames... why?
- airstrike 7y agoI never said it was a good idea!
- beagle3 7y agoSo you are writing hundreds of rename rules. Well, unlike treeform, I like it to be: api_call(system_call.inspect_something()) Which I find much more readable. What now?
- deleted 7y ago[deleted]
- lmm 7y agoIIRC a study on beginners learning Python found that case sensitivity was the biggest source of errors/confusion. So I'm all for new languages being case-insensitive.
- Riverheart 7y agoNot true. Powershell is mainstream and case insensitive. Never ran into an issue with it or heard of people complaining about it.
- nimmer 7y agoIt's shocking how people whine about case insensitivity without bothering to try using Nim for a while. Case insensitivity is a feature and it's meant to allow easy interfacing with C. And it also encourages clean code. With other languages you can have variables called "startdate", "start_date" and "startDate" in the same scope leading to bugs - especially when using completion in an editor - and poor readability. In Nim the compiler tells you that you are redefining the same variable in 3 different places and you can go and give them more meaningful names.
- fluffything 7y ago> In Nim the compiler tells you that you are redefining the same variable in 3 different places and you can go and give them more meaningful names. If this is the goal, there are many alternative ways to solve this problem, making the language case insensitive is a pretty big hammer.
- beagle3 7y agoSee gtrs' comment above[0]. Why do you assume case sensitivity is "the right thing"? [0] https://news.ycombinator.com/item?id=21403387 https://news.ycombinator.com/item?id=21403387
- pjbk 7y agoSome of us work in regulated industries where coding standards are not strong suggestions but unconditional requirements. Unambiguous names and identifiers precludes the use of Nim as a tool in any of those fields just by an improper design decision. Sounds very bad and completely avoidable to me. There is a reason old languages were many times case insensitive but not anymore.
- pfranz 7y agoI'm confused how unconditional requirements would preclude Nim? If anything, this allows you to use your "house style" internally and still interact with libraries who don't. I haven't used Nim, but I imagine that was the intention because that's when I've had to mix styles in other languages. To keep your own code consistent you just need your own linter/formatter, which if you have a strict style you're probably already doing.
- gtrs 7y agoNim is written in Nim and no one has run into this style insensitivity confusion despite many people contributing. If your project is smaller or fewer people and you still think this is a big issue, good luck. And if it is larger, this is the least of your concerns. Think in reverse, is it a useful language feature to have MyNimName, mynimname, MY_NIM_NAME, My_Nim_Name, __MYNIM___name_ be different? When did you need this flexibility recently? Are we really so limited at naming things appropriately? It's fine to make a big deal about something in theory but if it really was such a dumb idea it would have died over the decade Nim has been around. It was debated again prior to 1.0 and persisted, several good reasons are also mentioned in this thread. And it isn't even an original idea as brought up by several others. If this is the reason someone doesn't try Nim then it's only unfortunate for them. Add this to the tabs vs. spaces, curlies vs. whitespace indentation or other so called concerns which make no difference in the grand scheme of things.