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

deprecate any (redundant with auto) #281

Closed
timotheecour opened this issue Nov 5, 2020 · 9 comments · Fixed by nim-lang/Nim#16920
Closed

deprecate any (redundant with auto) #281

timotheecour opened this issue Nov 5, 2020 · 9 comments · Fixed by nim-lang/Nim#16920

Comments

@timotheecour
Copy link
Member

https://nim-lang.github.io/Nim/manual.html claims:

any | distinct auto (see below)

but then doesn't show examples with any.
And in fact this seems incorrect:

when true:
  proc main1(a, b: any)=discard
  proc main2(a, b: auto)=discard
  main1(1,"x") # works
  main2(1,"x") # works

so any seems redundant with auto, unless I'm missing something.
(docs also mention this: https://nim-lang.github.io/Nim/manual.html#templates-symbol-binding-in-templates

For parameters it currently creates implicitly generic routines:
proc foo(a, b: auto) = discard
Is the same as:
proc foo[T1, T2](a: T1, b: T2) = discard

it's also not used (much/at all) IIRC and is underdocumented.

note

docs also says:

However, later versions of the language might change this to mean "infer the parameters' types from the body". Then the above foo would be rejected as the parameters' types can not be inferred from an empty discard statement.

but IMO a pragma should be used for that instead of changing meaning of auto

note 2

docs should add right here:
typedesc is a "bind many" type class:

that auto is also "bind many"

@timotheecour timotheecour changed the title deprecate any and tyAnything (redundant with auto) deprecate any (redundant with auto) Nov 5, 2020
@cooldome
Copy link
Member

cooldome commented Nov 6, 2020

any is shorter and more accurate name for a type, should we decom auto instead

@Vindaar
Copy link

Vindaar commented Nov 6, 2020

To me any is a pretty scary thing. I wasn't even aware of its existence (talk about under documented) until a master's student of mine started using it in her code.
To me it's too close to making it seem like Nim is a dynamic language, i.e. people using it not realizing that it's "just" an implicit generic and then getting confused about resulting errors etc.

It's kinda neat that Nim allows to write code that looks so little like typed code, but... Who would honestly use any instead of a completely unrestricted generic?

@timotheecour
Copy link
Member Author

timotheecour commented Nov 6, 2020

any is shorter and more accurate name for a type, should we decom auto instead

auto is widespread, and common in other languages; it's here to stay.

...talk about under documented...

yes

Who would honestly use any instead of a completely unrestricted generic?

same holds for auto though. But it's useful, you just need to read the docs about what auto means as a param. That can be made easy if theindex.html starts indexing keywords like auto.

proc fn[T1,T2](a1: T1, a2: T2) = discard
proc fn(a1, a2: auto) = discard # shorter, and makes sense if you're not using T1, T2

@treeform
Copy link

treeform commented Jan 7, 2021

I support removal of any in favor of just having auto.

Also any type conflicts with function std lib any ( https://nim-lang.org/docs/sequtils.html#any%2CopenArray%5BT%5D%2Cproc%28T%29 ).

Which leads to some strange errors and crashes: nim-lang/Nim#14255

@juancarlospaco
Copy link
Contributor

Deprecation of any should start ASAP then.

@timotheecour
Copy link
Member Author

@juancarlospaco can you please make a PR?

@juancarlospaco
Copy link
Contributor

nim-lang/Nim#16920

@ringabout
Copy link
Member

ringabout commented Feb 9, 2021

Which leads to some strange errors and crashes: nim-lang/Nim#14255

auto causes the same issues too

block:
  var a = newSeq[bool](1000)
  if false:
    echo "ok?"
  elif auto(a):
    echo "false"

Error: internal error: getTypeDescAux(tyFromExpr)
No stack traceback available

@timotheecour
Copy link
Member Author

any was also confusing (in the human sense, not compiler sense) with typeinfo.Any refs https://nim-lang.github.io/Nim/typeinfo.html#Any

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants