4 ms·
Why? What inherent advantage do those languages have with financial logic?
by quaunaut 3y ago
Why? What inherent advantage do those languages have with financial logic?
- notpachet 3y agoBetter static analysis, for one.
- quaunaut 3y agoAnd that helps in financial analysis how?
- notpachet 3y agoI didn't say anything about financial analysis. But static typing is a good defense mechanism against type errors at runtime (I don't think anyone would argue against that). When you're running a financial services product, the cost of a type error in production can be dramatically higher than in non-financial code. Speaking from firsthand experience.
- IshKebab 3y agoI don't think it's specific to financial services. He just meant that financial services is an area where you really don't want bugs! And one of the easiest ways to eliminate entire classes of bugs is to use static typing.
- jakewins 3y agoWe have services in Python and C# at $dayjob, and my experience is that Python has mostly left C# behind here - what is something you can express in the C# type system that MyPy cannot statically check? Conversely, I find myself constrained by C#'s typesystem not having features now widely popular from Rust and Typescript and available in modern Python: const generics / literals, protocols/structural interfaces and matching over algebraic datatypes, to name a few examples.
- neonsunset 3y agoWas bewildered when reading this message. How come? Python and TypeScript by definition don't have a concept of const generics the way it applies to C++ templates or Rust. Nor "matching over algebraic datatypes" made any sense - sure sounds slightly below average fancy but comes down to just using C# pattern matching effectively, which the author may have never done. But then it struck me "structural interfaces sure sounds familiar", I go check the pinned repositories in the github profile and it all made sense immediately - the pinned ones are written in Go, which explains the author's woes with confidently navigating something more sophisticated.
- jakewins 3y agoSorry - can you put the snark aside and answer the question then, it seems given my lack of understanding here as a mere Go simpleton it should be trivial for you. The question I responded to said: "Better static analysis, for one." I asked: "What is something you can express in the C# type system that MyPy cannot statically check?" Can you provide some examples where C#'s type system can express something that modern well-typed Python cannot type-check?
- jakewins 3y ago> Python and TypeScript by definition don't have a concept of const generics the way it applies to C++ templates or Rust. Can you help guide me where I'm misunderstanding the type system aspect of const generics that's missing in Python? What I meant was that in Python I can say something like this: import typing as t class FooEater[NUM_FOOS: int]: def eat_foo(self, num_foos: NUM_FOOS): print("nomnom") one_foo = FooEater[t.Literal[1]]() one_foo.eat_foo(2) # type error, NUM_FOOs for one_foo only allows literal '1' And a PEP695-compatible typechecker will error at build time, saying I can't call `eat_foo` with `2`, because it's constrained to only allow the value `1`. I admit to not being a type system specialist, but at least as I understand Rust's "const generics" the type system feature is: "Things can be generic over constant values". Isn't that the same as what Python supports?
- DonnyV 3y agoPython will let you use float division on integers. Compiled type languages won't do that. This would be solved by using a double data type. But python doesn't have it.
- quaunaut 3y agoYou'd almost certainly just use a library dedicated to mitigating this problem though, of which there are many.
- DonnyV 3y agoOr you could just use a language with a static type system and avoid a whole class of bugs automatically.
- quaunaut 3y agoLook, I like static type systems, but not all type systems are created equal, and some(with the easiest example being Go) are downright awful for helping encode business logic, forcing you to write immense amounts of code just to work around their awful type system decisions, code that often introduces bugs because of those issues.
- Izkata 3y agoYou prooobably don't want to use doubles with financial data. Even in Java. Go for BigDecimal instead, for arbitrary precision instead of floating-point math. And if you're doing that, python has the Decimal class for the same thing.