26 ms·
Mundane typing? Typing is awesome! Haven't you ever wondered what a parameter actually is in say, Python, and have to track back through callers to work out wha
by arc776 8y ago
Mundane typing? Typing is awesome! Haven't you ever wondered what a parameter actually is in say, Python, and have to track back through callers to work out what the parameter is expected to contain? Completely solved by specifying type.
Nim has really good type inference, so the 'mundane' aspect I guess you're referring to isn't there.
let
myStr = "Hello"
myInt = 12
myFloat = 1.2
var myHashTable = newTable[string, int]()
The need for checking types at runtime is of course completely eliminated in typed languages so you get that for free. Nim also offers an extension to this with distinct types.
type
Euros = distinct float # NB: Don't use float for currency
Dollars = distinct float
let
a = 10.Dollars
b = 10.Euros
c = a + b # Compile time error
d = a + 1 # Compile time error
proc dollars(e: Euros): Dollars =
let exchangeRate = 1.117
result = (e.float * exchangeRate).Dollars
proc euros(d: Dollars): Euros =
let exchangeRate = 0.858
result = (d.float * exchangeRate).Euros
let
e = a.euros
f = b.dollars
echo e.float # 8.58
echo f.float # 11.17
> I have come to believe transpiling is the devil and many-languages syndrome is very counterproductive
Why do you believe this? In Nim the language creates an AST and it's this that is output in various forms. The underlying representation is the same, but it allows many targets. Similar to LLVM (which is also a Nim target, if unofficially), it's one of the reasons why it can compile on almost every platform, and why it is a good choice for the low resource devices that projects like Nimbus target.
It also means you can write servers and clients in the same language but target C and JavaScript, respectively.
- erikpukinskis 8y ago> > I have come to believe transpiling is the devil and many-languages syndrome is very counterproductive > Why do you believe this? In isolation it’s fine. But when I look at the complete toolchains required to maintain “modern” applications it’s not ok. There are too many different languages in a single application, too many declarative configuration surfaces, too many chained pipes. I grew up in a time where you wrote code, compiled and ran. We are overdue for a major collapse of how deep tooling is tolerable for a simple roundtrip source change. If you’re a pro developer (and I assume you are) then you can ignore this. You can afford to spend 40 hours debugging your toolchain, teaching through 5 different languages and configuration environments to locate a problem. But tolerable isn’t good enough for me. Frankly, I’m tired of spending my time slogging though DSL after DSL and runtime after runtime. I miss just code. I believe we are overdue for a resurgence of native languages that can be written just as pure compiled or intetpreted code without a stockade of bizarre executables propping them up.