You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I really like python style f strings, as below. This drastically improves readability over using the older format method.
name="Eric"age=74# f stringsprint( f"Hello, {name}. You are {age}.")
'Hello, Eric. You are 74.'# older format methodprint("Hello, %s. You are %d".format(name, age))
'Hello, Eric. You are 74.'
This has the obvious benefit of higher readability (A core design decision of Go) and also scales better as the strings that one deals with become longer and more complicated (another core design decision of Go). Please notice also that using {age} gives the string context that it otherwise wouldn't have if you were only skim reading the string (and of course ignoring the type that was specified), the string could have ended "You are tall", "You are [at XXX location]", "You are working too hard" and unless you put in the mental energy to map the format method to each instance of interpolation it isn't immediately obvious what should go there. By removing this (admittedly small) mental hurdle the programmer can focus on the logic rather than the code.
I was wondering if others shared my interest for a similar implementation in Go, of course with strict type formatting it couldn't look exactly the same but purely as a jumping off point is an implementation of roughly shape below possible?
name:="Eric"age:=74fmt.println("Hello %s{name}. You are %d{age}")
'Hello, Eric. Youare74.'
The text was updated successfully, but these errors were encountered:
I really like python style f strings, as below. This drastically improves readability over using the older format method.
This has the obvious benefit of higher readability (A core design decision of Go) and also scales better as the strings that one deals with become longer and more complicated (another core design decision of Go). Please notice also that using {age} gives the string context that it otherwise wouldn't have if you were only skim reading the string (and of course ignoring the type that was specified), the string could have ended "You are tall", "You are [at XXX location]", "You are working too hard" and unless you put in the mental energy to map the format method to each instance of interpolation it isn't immediately obvious what should go there. By removing this (admittedly small) mental hurdle the programmer can focus on the logic rather than the code.
I was wondering if others shared my interest for a similar implementation in Go, of course with strict type formatting it couldn't look exactly the same but purely as a jumping off point is an implementation of roughly shape below possible?
The text was updated successfully, but these errors were encountered: