Timeline for Why do you have to specify the data type when declaring variables?
Current License: CC BY-SA 3.0
10 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| S Mar 23, 2016 at 12:16 | history | suggested | psmears | CC BY-SA 3.0 | Fix a few typos |
| Mar 23, 2016 at 11:42 | review | Suggested edits | |||
| S Mar 23, 2016 at 12:16 | |||||
| Mar 23, 2016 at 0:16 | comment | added | Erik Eidt | @Ben, ok, great point! I've removed the emotion. | |
| Mar 23, 2016 at 0:15 | history | edited | Erik Eidt | CC BY-SA 3.0 | deleted 7 characters in body |
| Mar 22, 2016 at 21:24 | comment | added | Ben | "Implicit local types, explicit interface types" is how a lot of people program, even in languages like Haskell that allow you to omit (nearly) all types while still having the compiler infer strict types. There are many people who don't consider it sad when a language enforces this practice (as C# does). | |
| Mar 22, 2016 at 19:49 | comment | added | Roujo | @SergioTulentsev That's not true - in F#, you can have public methods without specifying their types explicitly. The compiler will infer the types from usage inside the method. For example, the following are valid public method definitions: static member add x y = x + y, member x.Append s = x.Text + s. In the first case, x and y will be inferred to be ints because of the addition. In the second case they'll be whatever is valid depending on the type of x.Text - if it's a string, then s will be a string as well. I do agree that type annotations are documentation, though. | |
| Mar 22, 2016 at 5:47 | comment | added | jfs | Note: you answer assumes that a language used to specify types is somehow better at avoiding errors than your regular programming language. It is obviously not so e.g., consider C++ template language that is Turing-complete (and therefore allows to express many error checks) but it is almost unreadable compared to many other Turing-complete languages such as Haskell, Python, and even other parts of C++ itself. Ask yourself why won't you use the same programming language, to express the error checks as the rest of your program (there are good answers in some but not all cases). | |
| Mar 21, 2016 at 20:04 | comment | added | txtechhelp | I think you should highlight/bold this line: Types are part of a system of checks that ... since it directly answers the OP on Why do we have to specify data type at all? .. | |
| Mar 21, 2016 at 13:37 | comment | added | Sergio Tulentsev | RE the sad part: It is impossible to infer type of a publicly accessible member (public field, public method signature), because you can't predict when and how it will be used. Also, type annotations are documentation. | |
| Mar 21, 2016 at 0:37 | history | answered | Erik Eidt | CC BY-SA 3.0 |