create account

Types, you can't do much without them by iobates

View this thread on: hive.blogpeakd.comecency.com
· @iobates ·
$9.55
Types, you can't do much without them
# 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

![javaScriptLogo.jpg](https://steemitimages.com/DQmXHjfQ6vehRQGW8yse9rWPj7hbUCkLCWSUXWU6FKECB55/javaScriptLogo.jpg)
[credit](http://www.killersites.com)
would think nothing of this and give you the obvious answer **a1**

### Python

![python-powered-w-200x80.png](https://steemitimages.com/DQmTeKWwSE8LEJVcYHYTv6WS5yUAHW7RdtnkHCQuBGqZtYu/python-powered-w-200x80.png)
[credit](http://python.org
Python is strongly typed dynamically, so python would yield a run-time error here

### Haskell
![Haskell-Logo.png](https://steemitimages.com/DQmTjXGbWEHKzRUwyBKeyRTJJ3QKaUoLMb3daT1bRW2jpe6/Haskell-Logo.png)
[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
![C2BProgramming2Blanguages.png](https://steemitimages.com/DQmW1v553KjqYVaHY4JaMMr7R6rRy92jHq3kRmSrxxfjq2i/C2BProgramming2Blanguages.png)
[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.
👍  , , , , , , ,
properties (23)
authoriobates
permlinktypes-you-can-t-do-much-without-them
categoryprogramming
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"}
created2017-07-01 15:10:15
last_update2017-07-01 15:10:15
depth0
children16
last_payout2017-07-08 15:10:15
cashout_time1969-12-31 23:59:59
total_payout_value7.534 HBD
curator_payout_value2.015 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length3,449
author_reputation9,228,087,136,240
root_title"Types, you can't do much without them"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id6,901,241
net_rshares1,140,812,667,414
author_curate_reward""
vote details (8)
@adnanrahic ·
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.
properties (22)
authoradnanrahic
permlinkre-iobates-types-you-can-t-do-much-without-them-20170701t171848699z
categoryprogramming
json_metadata{"tags":["programming"],"app":"steemit/0.1"}
created2017-07-01 17:18:54
last_update2017-07-01 17:18:54
depth1
children11
last_payout2017-07-08 17:18:54
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length205
author_reputation1,605,311,705,685
root_title"Types, you can't do much without them"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id6,915,068
net_rshares0
@iobates ·
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.
properties (22)
authoriobates
permlinkre-adnanrahic-re-iobates-types-you-can-t-do-much-without-them-20170701t172133403z
categoryprogramming
json_metadata{"tags":["programming"],"app":"steemit/0.1"}
created2017-07-01 17:21:30
last_update2017-07-01 17:21:30
depth2
children10
last_payout2017-07-08 17:21:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length144
author_reputation9,228,087,136,240
root_title"Types, you can't do much without them"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id6,915,389
net_rshares0
@adnanrahic ·
True. But I still love it. :)
properties (22)
authoradnanrahic
permlinkre-iobates-re-adnanrahic-re-iobates-types-you-can-t-do-much-without-them-20170701t172447622z
categoryprogramming
json_metadata{"tags":["programming"],"app":"steemit/0.1"}
created2017-07-01 17:24:54
last_update2017-07-01 17:24:54
depth3
children9
last_payout2017-07-08 17:24:54
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length29
author_reputation1,605,311,705,685
root_title"Types, you can't do much without them"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id6,915,767
net_rshares0
@qed ·
$0.04
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!
👍  
properties (23)
authorqed
permlinkre-iobates-types-you-can-t-do-much-without-them-20170701t194146427z
categoryprogramming
json_metadata{"tags":["programming"],"links":["https://steemit.com/programming/@qed/type-driven-development-idris-1"],"app":"steemit/0.1"}
created2017-07-01 19:41:48
last_update2017-07-01 19:41:48
depth1
children1
last_payout2017-07-08 19:41:48
cashout_time1969-12-31 23:59:59
total_payout_value0.034 HBD
curator_payout_value0.010 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length223
author_reputation371,686,564,844
root_title"Types, you can't do much without them"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id6,930,127
net_rshares5,485,622,690
author_curate_reward""
vote details (1)
@iobates ·
$0.04
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
👍  
properties (23)
authoriobates
permlinkre-qed-re-iobates-types-you-can-t-do-much-without-them-20170701t200922897z
categoryprogramming
json_metadata{"tags":["programming"],"app":"steemit/0.1"}
created2017-07-01 20:09:21
last_update2017-07-01 20:09:21
depth2
children0
last_payout2017-07-08 20:09:21
cashout_time1969-12-31 23:59:59
total_payout_value0.032 HBD
curator_payout_value0.010 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length208
author_reputation9,228,087,136,240
root_title"Types, you can't do much without them"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id6,932,690
net_rshares5,394,700,767
author_curate_reward""
vote details (1)
@ragequit ·
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 :)
properties (22)
authorragequit
permlinkre-iobates-types-you-can-t-do-much-without-them-20170702t111739291z
categoryprogramming
json_metadata{"tags":["programming"],"app":"steemit/0.1"}
created2017-07-02 11:17:42
last_update2017-07-02 11:17:42
depth1
children1
last_payout2017-07-09 11:17:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length243
author_reputation84,968,448,410
root_title"Types, you can't do much without them"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id6,999,953
net_rshares0
@iobates ·
Nice, perhaps I should write something else like this.
properties (22)
authoriobates
permlinkre-ragequit-re-iobates-types-you-can-t-do-much-without-them-20170705t214600776z
categoryprogramming
json_metadata{"tags":["programming"],"app":"steemit/0.1"}
created2017-07-05 21:46:00
last_update2017-07-05 21:46:00
depth2
children0
last_payout2017-07-12 21:46:00
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length54
author_reputation9,228,087,136,240
root_title"Types, you can't do much without them"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id7,446,023
net_rshares0