{"action":"created","issue":{"url":"https://api.github.com/repos/nim-lang/Nim/issues/7519","repository_url":"https://api.github.com/repos/nim-lang/Nim","labels_url":"https://api.github.com/repos/nim-lang/Nim/issues/7519/labels{/name}","comments_url":"https://api.github.com/repos/nim-lang/Nim/issues/7519/comments","events_url":"https://api.github.com/repos/nim-lang/Nim/issues/7519/events","html_url":"https://github.com/nim-lang/Nim/issues/7519","id":311893825,"number":7519,"title":"[meta issue] make all Nim APIs generic: ctor, init, to, streams, types, etc","user":{"login":"timotheecour","id":2194784,"avatar_url":"https://avatars2.githubusercontent.com/u/2194784?v=4","gravatar_id":"","url":"https://api.github.com/users/timotheecour","html_url":"https://github.com/timotheecour","followers_url":"https://api.github.com/users/timotheecour/followers","following_url":"https://api.github.com/users/timotheecour/following{/other_user}","gists_url":"https://api.github.com/users/timotheecour/gists{/gist_id}","starred_url":"https://api.github.com/users/timotheecour/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timotheecour/subscriptions","organizations_url":"https://api.github.com/users/timotheecour/orgs","repos_url":"https://api.github.com/users/timotheecour/repos","events_url":"https://api.github.com/users/timotheecour/events{/privacy}","received_events_url":"https://api.github.com/users/timotheecour/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-04-06T08:44:02Z","updated_at":"2018-04-06T10:13:35Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"All these will simplify some API's by making them generic with less duplication:\r\n\r\n- [ ] constructors: https://github.com/nim-lang/Nim/issues/7474 newFoo[T](args) => Foo.New[T](args)\r\n- [ ] initializers: (TODO: file issue) initFoo[T](args) => Foo.Init[T](args)\r\n- [ ] converters/parsers: https://github.com/nim-lang/Nim/issues/7430 a.parseBool => a.to[bool] or a.parse[bool]\r\n- [ ] streams: https://github.com/nim-lang/Nim/pull/7481 readBool => read[bool]\r\n- [ ] macros.nim: nnkInt32Lit => nnkLit[int32] (eg will simplify `newLit`, etc)\r\n- [ ] typeinfo.nim: getUInt32  => getType[uint32]\r\n\r\n## NOTE about `generic` meaning\r\nNim generics can be overloaded (eg: `proc foo[T:int|bool]()` or even with `proc foo[T:isConceptBar]()` unlike java generics, so the term can be confusing for some and indeed it tripped a few people recently (eg https://github.com/nim-lang/Nim/issues/7430#issuecomment-377473190 , https://github.com/nim-lang/Nim/issues/3502#issuecomment-378292623 ), maybe Nim docs could clarify this aspect. The point is we want to have generic (in Nim's sense of overloadable generics) APIs as much as possible, as legacy API's like `parseBool` make generic code hard to use (API writer needs special case for each type eg bool), reminiscent of C and go.\r\n\r\n## tell-tell sign that generic api's are needed:\r\nlots of very similar code blocks repeated for several distinct types\r\n\r\neg: in macros.nim:\r\n```\r\nproc newLit*(i: int32): NimNode {.compileTime.} =\r\n  ## produces a new integer literal node.\r\n  result = newNimNode(nnkInt32Lit)\r\n  result.intVal = i\r\n\r\nproc newLit*(i: int64): NimNode {.compileTime.} =\r\n  ## produces a new integer literal node.\r\n  result = newNimNode(nnkInt64Lit)\r\n  result.intVal = i\r\n# etc (lots of overloads)\r\n```\r\n\r\ncould become simply:\r\n```\r\nproc newLit*[T](i: T): NimNode {.compileTime.} =\r\n  result = NimNode.New(nnkLit[T])\r\n  result.val[T] = i\r\n```\r\n## how to rewrite API's (typedesc vs generics) ?\r\nhttps://github.com/nim-lang/Nim/issues/7517 [RFC] guidelines for when to use typedesc vs generics\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/nim-lang/Nim/issues/comments/379210973","html_url":"https://github.com/nim-lang/Nim/issues/7519#issuecomment-379210973","issue_url":"https://api.github.com/repos/nim-lang/Nim/issues/7519","id":379210973,"user":{"login":"Araq","id":287816,"avatar_url":"https://avatars1.githubusercontent.com/u/287816?v=4","gravatar_id":"","url":"https://api.github.com/users/Araq","html_url":"https://github.com/Araq","followers_url":"https://api.github.com/users/Araq/followers","following_url":"https://api.github.com/users/Araq/following{/other_user}","gists_url":"https://api.github.com/users/Araq/gists{/gist_id}","starred_url":"https://api.github.com/users/Araq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Araq/subscriptions","organizations_url":"https://api.github.com/users/Araq/orgs","repos_url":"https://api.github.com/users/Araq/repos","events_url":"https://api.github.com/users/Araq/events{/privacy}","received_events_url":"https://api.github.com/users/Araq/received_events","type":"User","site_admin":false},"created_at":"2018-04-06T10:13:35Z","updated_at":"2018-04-06T10:13:35Z","author_association":"OWNER","body":"I prefer a langauge with a low barrier to entry though. A standard library does not have to be a strange beast that uses every feature the language offers."}}
{"actor":{"display_login":"Araq"}}