Praise for Go despite being statically typed language

Back to General discussions forum

oezguery     2023-08-17 22:06:11
User avatar

Hi friends! I would like to expres my astonishment how it can become quick to solve puzzles with Go.

Being a statically typed language it is actually quite cumbersome to get set up with Go to read input, parse it and convert from string to target type and after the calculations convert everything back to string again to be printed.

However, the more you advance, the more ideas you come up with. For example, to encapsulate the repetitive preparation code, aka boiler plate, and separate it to another file and adjust from time to time.

More importantly, the praise I want to sing for Go is that it amazes me how far less runtime exceptions I am encountering while developing the solutions. In Python it is normal to start with some code that presents results, and developing mostly involves removing logic errors, extending the logic and handling exceptions. And there are many of them.

In Go I noticed I am very conscious of the types and try a lot to get them right, but then once the code runs it is most of the time the solution as well, not much development on the go necessary.

Would you agree? What is your experience with your programming language?

Rodion (admin)     2023-08-18 06:28:38
User avatar

it is actually quite cumbersome to get set up with Go to read input, parse it and convert from string to target type

Not as cumbersome as with Rust :) I have got some acquaintance with it roughly at the same time as with Go, but the language is next degree of complication. Though it is not just for fancy, Rust introduces very unusual memory model, much more safe against memory leaks and inefficient usage at all.

it amazes me how far less runtime exceptions I am encountering while developing the solutions

Probably it is one of main points behind "strict and static types". You spend more time writing and less time debugging.

Languages dramatically differ in this regard - Java, C# and Go all emphasize this approach. Once I was writing test project for some job position in Haskell - I was enraged by its strictness out of my wits. If the value was read from console, for example, it is regarded as, say, int of some "potentially spoiled" type, and every calculation involving it will produce result of similarly "potentially spoiled" type. This feels like a bit overkill in strictness.

On the other hand Python is not yet the least strict. You may have noticed it won't allow join on the list of integers etc. With JS, PHP, Perl or Lua it is not a problem - value will work both as string or number depending on situation.

Overall I'd say it is more about programmer's experience and preference. Though generally languages with slack typisation are scripting ones and significantly slower. On the other hand scripting languages provide more flexibility.

There are situations when strict typing is painful, when one needs to add dynamic fields to structures - say, when dealing with records from database or parsing JSON. The best option is to use maps/dicts instead of structures, but with Go you'll find it is still painful (every field then needs to be converted to some proper type). General approach is to define necessary structures beforehand (even using code-generating tools), which makes development process somewhat tedious.

Please login and solve 5 problems to be able to post at forum