# Why does Types matter in programming ## Possibilities Typing happens on two axis, there is the **dynamic vs static**, and then there is the **strong vs weak**. If you program in python you are programming with **strong** typing, which is good, but you are also using dynamic which might be a little annoying. ## Dynamic or Static This is a binary there is no degree to which it is dynamic, either you are or you aren't. The way this works is if you happen to be in a dynamic language and you want a variable This example would be in **Python** > a = 1 There is not a type in sight, but it is still strongly typed. The next example I will be presenting is in **Java** > Int a = 1; That is not so bad, but it can get really bad with the Types, that is clearly worse, but there is a clever solution to this problem, meet **Haskell** which is probably the programming language with the strongest typing and also with static typing. In Haskell to declare something to be Int as the two examples above > a = 1 But wait why is there no declaration ? Simple **Haskell** has Type-Inference meaning it can infer the type of code typed in, but good style of the above code would be > a :: Int a = 1 where **::** means *has type*, basically the compiler takes all your Type Declarations and throw them out, then it figures out the types for itself and sees if you are right. <hr> Dynamic typing is the computing tacking a value with the type onto a thing, probably coming from the value you used as input, the statically typing require you to give types, or have a type inference work it out for you. ## Strong vs Weak Typing **Strong vs Weak** Typing is not a binary, it can be in between, **Haskell** would be one of the most **strongly** typed languages, and on the other side something like **Javascript** would be one of the most **weakly** typed languages. To investigate how **strong** typing helps programmers the following snippet > "a" + 1 would be handled very differently in different languages. ### Javascript  [credit](http://www.killersites.com) would think nothing of this and give you the obvious answer **a1** ### Python  [credit](http://python.org Python is strongly typed dynamically, so python would yield a run-time error here ### Haskell  [credit](https://wiki.haskell.org/Haskell_logos) Haskell being both statically typed and strongly typed would yield a compile-time error, this would be the ideal situation you get the error before even running the code. That way no buggy can possibly run in production. ### C  [credit](https://pt.stackoverflow.com/questions/166634/como-mudar-uma-imagem-clicando-em-um-link) C really has weird ideas about how to coerce types, the weirdest happens when you do something a little different > "hello" - 1 here C does the obvious thing and returns > "hell" well wasn't that what you wanted ? Well kidding aside, this type coercion is a big problem when weak typing is used.
author | iobates |
---|---|
permlink | types-you-can-t-do-much-without-them |
category | programming |
json_metadata | {"tags":["programming","theory","types","typing","writing"],"image":["https://steemitimages.com/DQmXHjfQ6vehRQGW8yse9rWPj7hbUCkLCWSUXWU6FKECB55/javaScriptLogo.jpg","https://steemitimages.com/DQmTeKWwSE8LEJVcYHYTv6WS5yUAHW7RdtnkHCQuBGqZtYu/python-powered-w-200x80.png","https://steemitimages.com/DQmTjXGbWEHKzRUwyBKeyRTJJ3QKaUoLMb3daT1bRW2jpe6/Haskell-Logo.png","https://steemitimages.com/DQmW1v553KjqYVaHY4JaMMr7R6rRy92jHq3kRmSrxxfjq2i/C2BProgramming2Blanguages.png"],"links":["http://www.killersites.com","http://python.org","https://wiki.haskell.org/Haskell_logos","https://pt.stackoverflow.com/questions/166634/como-mudar-uma-imagem-clicando-em-um-link"],"app":"steemit/0.1","format":"markdown"} |
created | 2017-07-01 15:10:15 |
last_update | 2017-07-01 15:10:15 |
depth | 0 |
children | 16 |
last_payout | 2017-07-08 15:10:15 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 7.534 HBD |
curator_payout_value | 2.015 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 3,449 |
author_reputation | 9,228,087,136,240 |
root_title | "Types, you can't do much without them" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 6,901,241 |
net_rshares | 1,140,812,667,414 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
iobates | 0 | 25,705,491,904 | 100% | ||
shaka | 0 | 1,103,794,784,063 | 30% | ||
smasher | 0 | 1,678,566,461 | 30% | ||
cognitive | 0 | 1,486,694,464 | 100% | ||
velimir | 0 | 410,413,017 | 3% | ||
nv-vn | 0 | 5,606,851,921 | 100% | ||
ragequit | 0 | 1,096,852,668 | 100% | ||
qed | 0 | 1,033,012,916 | 100% |
Very nice explanation. Cool that you compared different languages. I recently wrote about type coercion and precise comparisons in JavaScript. Those are some very complex concepts to wrap your head around.
author | adnanrahic |
---|---|
permlink | re-iobates-types-you-can-t-do-much-without-them-20170701t171848699z |
category | programming |
json_metadata | {"tags":["programming"],"app":"steemit/0.1"} |
created | 2017-07-01 17:18:54 |
last_update | 2017-07-01 17:18:54 |
depth | 1 |
children | 11 |
last_payout | 2017-07-08 17:18:54 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 205 |
author_reputation | 1,605,311,705,685 |
root_title | "Types, you can't do much without them" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 6,915,068 |
net_rshares | 0 |
Javascript has some really weird behavior, it is not a good sign when you can make the language give different answers depending on how you ask.
author | iobates |
---|---|
permlink | re-adnanrahic-re-iobates-types-you-can-t-do-much-without-them-20170701t172133403z |
category | programming |
json_metadata | {"tags":["programming"],"app":"steemit/0.1"} |
created | 2017-07-01 17:21:30 |
last_update | 2017-07-01 17:21:30 |
depth | 2 |
children | 10 |
last_payout | 2017-07-08 17:21:30 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 144 |
author_reputation | 9,228,087,136,240 |
root_title | "Types, you can't do much without them" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 6,915,389 |
net_rshares | 0 |
True. But I still love it. :)
author | adnanrahic |
---|---|
permlink | re-iobates-re-adnanrahic-re-iobates-types-you-can-t-do-much-without-them-20170701t172447622z |
category | programming |
json_metadata | {"tags":["programming"],"app":"steemit/0.1"} |
created | 2017-07-01 17:24:54 |
last_update | 2017-07-01 17:24:54 |
depth | 3 |
children | 9 |
last_payout | 2017-07-08 17:24:54 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 29 |
author_reputation | 1,605,311,705,685 |
root_title | "Types, you can't do much without them" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 6,915,767 |
net_rshares | 0 |
Great topic, iobates! :) I just started a series on **Idris**, which you may call the **dependently typed** version of Haskell: https://steemit.com/programming/@qed/type-driven-development-idris-1 Keep up the good work!
author | qed |
---|---|
permlink | re-iobates-types-you-can-t-do-much-without-them-20170701t194146427z |
category | programming |
json_metadata | {"tags":["programming"],"links":["https://steemit.com/programming/@qed/type-driven-development-idris-1"],"app":"steemit/0.1"} |
created | 2017-07-01 19:41:48 |
last_update | 2017-07-01 19:41:48 |
depth | 1 |
children | 1 |
last_payout | 2017-07-08 19:41:48 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.034 HBD |
curator_payout_value | 0.010 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 223 |
author_reputation | 371,686,564,844 |
root_title | "Types, you can't do much without them" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 6,930,127 |
net_rshares | 5,485,622,690 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
nv-vn | 0 | 5,485,622,690 | 100% |
Yeah Idris is one of the cool things Haskellers look at, possibly like other people look at Haskell, a yet more expressive type system, I should have a look at that post, I might learn something I can use :-P
author | iobates |
---|---|
permlink | re-qed-re-iobates-types-you-can-t-do-much-without-them-20170701t200922897z |
category | programming |
json_metadata | {"tags":["programming"],"app":"steemit/0.1"} |
created | 2017-07-01 20:09:21 |
last_update | 2017-07-01 20:09:21 |
depth | 2 |
children | 0 |
last_payout | 2017-07-08 20:09:21 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.032 HBD |
curator_payout_value | 0.010 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 208 |
author_reputation | 9,228,087,136,240 |
root_title | "Types, you can't do much without them" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 6,932,690 |
net_rshares | 5,394,700,767 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
nv-vn | 0 | 5,394,700,767 | 100% |
This is good material, there are so many so called programmers nowadays that don't understand these aspects and they end up with code that looks like it's working but it's producing garbage data. Good tut, I'm subscribing to this material :)
author | ragequit |
---|---|
permlink | re-iobates-types-you-can-t-do-much-without-them-20170702t111739291z |
category | programming |
json_metadata | {"tags":["programming"],"app":"steemit/0.1"} |
created | 2017-07-02 11:17:42 |
last_update | 2017-07-02 11:17:42 |
depth | 1 |
children | 1 |
last_payout | 2017-07-09 11:17:42 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 243 |
author_reputation | 84,968,448,410 |
root_title | "Types, you can't do much without them" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 6,999,953 |
net_rshares | 0 |
Nice, perhaps I should write something else like this.
author | iobates |
---|---|
permlink | re-ragequit-re-iobates-types-you-can-t-do-much-without-them-20170705t214600776z |
category | programming |
json_metadata | {"tags":["programming"],"app":"steemit/0.1"} |
created | 2017-07-05 21:46:00 |
last_update | 2017-07-05 21:46:00 |
depth | 2 |
children | 0 |
last_payout | 2017-07-12 21:46:00 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 54 |
author_reputation | 9,228,087,136,240 |
root_title | "Types, you can't do much without them" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 7,446,023 |
net_rshares | 0 |