## FROM TO
proc waitFor(socket: Socket, waited: var Duration, timeout, size: int,
funcName: string): int {.tags: [TimeEffect].} =
proc waitFor(socket: Socket, waited: var Duration, timeout, size: int,
funcName: string) -> int {.tags: [TimeEffect].}:
proc newContext*(protVersion = protSSLv23, verifyMode = CVerifyPeer, certFile = "", keyFile = "", cipherList = CiphersIntermediate,
caDir = "", caFile = "", ciphersuites = CiphersModern): SslContext =
var mtd: PSSL_METHOD
when defined(openssl10):
case protVersion
of protSSLv23:
mtd = SSLv23_method()
proc newContext*(protVersion = protSSLv23, verifyMode = CVerifyPeer, certFile = "", keyFile = "", cipherList = CiphersIntermediate,
caDir = "", caFile = "", ciphersuites = CiphersModern) -> SslContext:
var mtd: PSSL_METHOD
when defined(openssl10):
case protVersion
of protSSLv23:
mtd = SSLv23_method()
proc pskClientCallback(ssl: SslPtr; hint: cstring; identity: cstring;
max_identity_len: cuint; psk: ptr uint8;
max_psk_len: cuint): cuint {.cdecl.} =
let ctx = SslContext(context: ssl.SSL_get_SSL_CTX)
proc pskClientCallback(ssl: SslPtr; hint: cstring; identity: cstring;
max_identity_len: cuint; psk: ptr uint8;
max_psk_len: cuint) -> cuint {.cdecl.}:
let ctx = SslContext(context: ssl.SSL_get_SSL_CTX)
for 2: this would then be inconsistent with variable declaration, which I think was the reason the syntax is like this in the first place
for 3: I don't think this is important as there are still other syntax elements which make it significantly different from Python
for 2: "... inconsistent with variable declaration"
I don't see an inconsistency between proc declaration (split between header and body of a proc) and a variable declaration/assignment? I would say it's something different. It's a beginning of a block, similar to "try, case, if" construct.
var a: array[0..1, char]
let i = 5
try:
a[i] = 'N'
except IndexDefect:
echo "invalid index"
for 3: "Less differences" makes switch easier.
CONS: Little bit more typing:
): ) ->
For 3, Nim is not Python, nor is it trying to be Python, also I heavily doubt Nim will change the syntax for proc definitions unless there's a definite fatal flaw
If you're looking for compiled Python, there's Cython, Nuitka and numerous other alternatives really
Also migrating from Python to Nim is a big task anyway, Python is dynamic while Nim is statically typed
I see increasing readability and consistency not as minor.
Migration path to a new Nim version ( 2.5 or 3.0). During this time both syntax variants could be allowed and the comiler prints a warning "deprecated ...". I think it should be even possible to use find/replace in the source code to change the code without manual help.
nimsuggest could support refactoring?
I can spot the consistency in:
proc f(): int = 3
let x: int = 4
var y: int = 5
With a bit of practice so can you.
It's not about transfering code from Python to Nim. Similar syntax to one of the most used prog langs would help to switch between Nim and Python.
But this should not be the reason to adapt the syntax. As I wrote I think in this case the syntax
) -> ___:
has a better readability and is more consistent with Nim. So it's simple: Compare the examples; Does the change help to overview and understand the code?
Does the change help to overview and understand the code?
No, it does not.
proc f(): int = 3
How often is something like this used? Isn't that const? Considering blocks I see procs (handling indentation) in this category:
const f: int = 3
## block: indentation
proc f(): int =
3
proc f() -> int:
3
block myblock:
echo "entering block"
while true:
echo "looping"
break
let name = readLine(stdin)
if name == "":
echo "Poor soul, you lost your name?"
elif name == "name":
echo "Very funny, your name is name."
else:
echo "Hi, ", name, "!"
## further example
proc communicate(greeting: proc (x: string): string, name: string) =
echo greeting(name)
proc communicate(greeting: proc (x: string) -> string, name: string):
echo greeting(name)
It's only a "nimsuggest" from my side. If you see an improvement in readability in all I think there are good arguments that procs can be seen as blocks, if, case, when statements.
Nim is now 2.0.0. And communities have been loving 'opinionated' softwares for a long time: for example, Black the python formatter, and Rails.
I think most people won't accept the possibility of this change, for it not only breaks the Nim way, but also breaks all written code.
Fwiw I sometimes think about this alternative syntax:
while a != b do
if x == y do
echo "yes"
else
echo "no"
mymacro a, b, c do
echo "code block passed to macro"
else
echo "else block also passed to macro"
But don't worry, I won't change anything.
This thread is surprisingly long. The idea is just bad on so many levels, it's really weird seeing such a vast discussion grow around it :-)
Wait until you hear my novel and unique idea that all Nim code should have mandatory 4-space indentation!