Why define variables in other languages

Discuss other programming languages besides AutoHotkey
gilliduck
Posts: 265
Joined: 06 Oct 2014, 15:01

Why define variables in other languages

30 Oct 2016, 16:50

Why is it that the bulk of other languages require you to define the type of data going into a variable instead of just letting it take whatever you put in? In AHK I can simply say var1 := "Text" or var1 := 2. In basically every other language I've seen I would have to set var1 as either some sort of text or integer or floating point or whatever have you.

What's the advantage/disadvantages of that? I prefer the simplicity of AHKs freeform variables, make life a lot easier for me.
User avatar
Capn Odin
Posts: 1352
Joined: 23 Feb 2016, 19:45
Location: Denmark
Contact:

Re: Why define variables in other languages

30 Oct 2016, 19:17

This way of handling types is mostly seen in scripting languages (not precompiled).

Advantages:
  • Allows the programer greater freedom, especially in regards to return values.
  • This freedom makes prototyping faster.
Disadvantages:
  • Requires overhead either computational or storage.
  • In funcions, if you require some specific data type you have to test the variable, Since you don't know what type of data it contains.
  • It is prone to cause errors in large projects with many contributors, due to the uncertain nature of the content of a variable.
It is a little late right now, so I have probably forgotten a lot of dis/advantages.

I personally don't like to work in big teams on projects with no static type checking.
Please excuse my spelling I am dyslexic.
guest3456
Posts: 3462
Joined: 09 Oct 2013, 10:31

Re: Why define variables in other languages

30 Oct 2016, 20:33

gilliduck wrote: In basically every other language I've seen I would have to set var1 as either some sort of text or integer or floating point or whatever have you.
you must not have seen very many programming languages then :)

gilliduck wrote:What's the advantage/disadvantages of that?
http://lmgtfy.com/?q=type+system

User avatar
tank
Posts: 3122
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: Why define variables in other languages

30 Oct 2016, 20:42

each language has a different way of allocating memory,
there is a whole science to understanding the differences. everything in ahk is basically declared as a string.
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
gilliduck
Posts: 265
Joined: 06 Oct 2014, 15:01

Re: Why define variables in other languages

31 Oct 2016, 14:14

guest3456 wrote:
gilliduck wrote: In basically every other language I've seen I would have to set var1 as either some sort of text or integer or floating point or whatever have you.
you must not have seen very many programming languages then :)

gilliduck wrote:What's the advantage/disadvantages of that?
http://lmgtfy.com/?q=type+system
dickwad
guest3456
Posts: 3462
Joined: 09 Oct 2013, 10:31

Re: Why define variables in other languages

31 Oct 2016, 17:30

gilliduck wrote: dickwad
ok next time i wont respond and you'll stay in the dark

User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Why define variables in other languages

06 Nov 2016, 06:24

He was asking here because, as he said, AHK is one of the only languages he knows of that doesn't require variable type declarations. So he thought he could get some good insight from AHK users. Then you basically tell him he shouldn't be posting that here; go google it. And you think your response helped enlighten him? I think he would be happy if you didn't respond next time.
User avatar
tank
Posts: 3122
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: Why define variables in other languages

06 Nov 2016, 12:14

I suppose i can get behind that boiler. i would add that while the posted link was a bit on the "intentional irritant" side, it did deliver a result on point of the ask. The problem is that this is not an answer to be discovered on a forum post. this is one of those questions that can only really be answered by an in depth exploration in the the subject of how languages allocate memory. While Capn Odin did an admirable job attempting a synopsis, i felt like it suffers from the same problem as the question. It can only take you to the looking glass and into wonderland. There is no short answer that can adequately explain it because in addition to the complexities of the subject and implementation differences, there is also the reasoning used by the individual language developer(s).
Let me give you an example
PHP is often and incorrectly considered a loosely typed or dynamically typed language. that's not the case. what it does instead is for any variable it allocates for each character into character arrays. it then takes the value assigned and applies ever reasonable variant type into its data type. when you ask for a cast of a string "15 this is a fabulous string" as int and get 15 the system performs a type juggling act to the int value in memory to get 15. it juggled out the first integers it found and ended its juggle when it encountered a non int. Its a bit psychotic and there are endless debates and questions on every php forum over the confusions that arise with php type juggling. It is one of the reasons that PHP ends up so hack-able in my opinion. Finally as of PHP 7 you can finally approach having the option to lock a variable into a type.

I probably confused someone with that poor explanation. but in understanding that you get some very implementation specific advantages and disadvantages. for one implementation the disadvantages of this from another implementation could be advantages
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
guest3456
Posts: 3462
Joined: 09 Oct 2013, 10:31

Re: Why define variables in other languages

07 Nov 2016, 21:33

boiler wrote:Then you basically tell him he shouldn't be posting that here; go google it.
no, that's not what i "basically told him".

what i basically told him was, 1. enlightened him that there are many other programming languages that are loosely typed besides AHK, and 2. showed him how he can find the answer himself, and probably get a better answer than anyone here will give, since most AHK users probably don't even know the difference.

give a man a fish, feed him for a day. teach him to fish, feed him for life.
boiler wrote: And you think your response helped enlighten him?
based on his reply, i'm sure my response didn't do a damn thing. and since im in the mood for quotes today, its apropos: no good deed goes unpunished


Return to “Other Programming Languages”

Who is online

Users browsing this forum: No registered users and 34 guests