I use both JS and Python for networking all the time and sometimes I wish there was just a first class way to say "these are u32" and "these are u128" because it can make things like this dead simple and blazing fast (pseudocode):
Number of IPs in a subnet is "~netmask + 1", network address of a host with a given netmask is "host & netmask", mask length to integer form is "0xFFFFFFFF << (32 - maskLength)", and so on. Subnet logic is all designed to be clear, lightweight, and fast from the ground up.
Of course it's also nice to have built in libraries like "ipaddress" too as most (if not all) of what you were wanting to do will likely already be done for you but in the cases it doesn't you're back to wishing you could just specify a type to save a lot of work.
Agreed. Python defaulting to magic bigints is nice when you're in a math domain, but terrible when in a computer domain. The stdlib really needs some nice simple u32(), i64() etc. constructors.
Comments
I use both JS and Python for networking all the time and sometimes I wish there was just a first class way to say "these are u32" and "these are u128" because it can make things like this dead simple and blazing fast (pseudocode):
Number of IPs in a subnet is "~netmask + 1", network address of a host with a given netmask is "host & netmask", mask length to integer form is "0xFFFFFFFF << (32 - maskLength)", and so on. Subnet logic is all designed to be clear, lightweight, and fast from the ground up.Of course it's also nice to have built in libraries like "ipaddress" too as most (if not all) of what you were wanting to do will likely already be done for you but in the cases it doesn't you're back to wishing you could just specify a type to save a lot of work.
Agreed. Python defaulting to magic bigints is nice when you're in a math domain, but terrible when in a computer domain. The stdlib really needs some nice simple u32(), i64() etc. constructors.