6 ms·
I will never forget the day that I spent debugging an early QBasic program that included a line similar to 5 = x for an assignment in the first draft. There
by ISL 6y ago
I will never forget the day that I spent debugging an early QBasic program that included a line similar to
5 = x
for an assignment in the first draft. There were tears and deep frustration at the moment I discovered that assignment had a directionality. The author's story brings back so many memories of learning and growth.
For those too young to know -- magazines used to come with page-long Basic programs for games that you could type in, debug (there were always typos), and play.
- phendrenad2 6y agoHonestly it's pretty strange that assignment has a directionality.
- sjwright 6y agoIt has to though. X = Y; // what should change?
- edejong 6y agoX_{t+1} = Y_t Doesn’t have to.
- dragonwriter 6y agoYou say nothing has to change, but what you write to support it is explicitly that X changes based on Y, since you are just making the time sequence explicit in the code instead of implicit in the operator syntax.
- fernmyth 6y agoIn a declarative language, nothing.
- pron 6y agoBut computation has an intrinsic directionality. If you have two expressions a, and b, and you want to unify them in a declarative language as a = b, then having an unknown subterm in one or the other can make the computation have a completely different complexity, making one direction easy and the other intractable. The P vs. NP problem is a famous question exactly about this directionality. Here's a simple example (in a declarative language that allows non-terminating computation; in a total language similar examples can be given, except "impossible" means intractable rather than non-computable, which, for all intents and purposes is the same): X = terminates?(P(1)) If X is known then finding a P is easy; if vice-versa, finding X is possibly impossible.
- phendrenad2 6y agoOh, I meant in the special case of something that can only be an r-value on the left such, such as a constant or function result. But yeah, it could still confuse newbies, because the problem is not understand that it's procedural.
- dragonwriter 6y agoWhichever isn't currently bound to a concrete value, or neither (except that they become bound to each other) if neither is; if both are, it's an error should occur, since they cannot be unified.
- ISL 6y agoThe primary difficulty that I had was the overloaded usage of the "=" character. I had a clear mathematical understanding that the "=" symbol was symmetric, that 5 = x and x = 5 were equivalent. That someone could abuse that notion so brazenly was the source of my frustration. Some languages use directional notation for assignment (see [1]): 5 -> x is clear. [1] https://en.wikipedia.org/wiki/Assignment_(computer_science)#Notation https://en.wikipedia.org/wiki/Assignment_(computer_science)#...
- teddyh 6y agoPascal and related languages use the notation x := 5 I have heard that this was to mimic (in ASCII) the look of an arrow: x ⇐ 5
- Wowfunhappy 6y agoMy first thought was, if they wanted an arrow why wouldn’t they go with: x <= 5 But of course, that means “less than or equal to”. You could do: x <- 5 But I suppose the mere presence of the “less than” symbol is weird in context. (Although, maybe not inherently weirder than using the equals sign for something other than equality?) Perhaps we would have been better off if we’d all just agreed early on, that @, #, or ~ should represent assignment.
- teddyh 6y agoThe original 1963 version of ASCII had a left-arrow (←) symbol, but it was replaced with underscore (_) in the 1965 version.
- magicalhippo 6y agoOne of the reasons I still quite like Pascal.
- Wowfunhappy 6y agoI know it's more verbose, but I'm deeply fond of Applescript's syntax for assigning variables: set x to 5
- nsenifty 6y agoThe first time I saw X = X + 1 in a ZX Spectrum basic program listing, I thought it would cause the computer to catch fire. I was 9 though.
- benttoothpaste 6y agoZx Spectrum was actually less confusing because it required LET before variable assignment.
- nsenifty 6y agoAh yes, it might have been GW-Basic then. My uncle had a ZX Spectrum I would play with but the books I could get were all for IBM PCs.
- myself248 6y agoMy dad was offended that such an algebraic abomination should be the way the computer represented things. I started putting the LET keyword in front (which was strictly optional), and it bothered him a lot less.
- superdisk 6y agoJust introduce your dad to Prolog.
- WalterBright 6y ago> I thought it would cause the computer to catch fire Star Trek taught at least a couple generations that if you pressed the wrong key or programmed in something illogical the keyboard would burst into flames and throw you across the room.