Why can’t variable names start with numbers?
Because then a string of digits would be a valid identifier as well as a valid number. int 17 = 497; int 42 = 6 * 9; String 1111 = “Totally text”;
Because then a string of digits would be a valid identifier as well as a valid number. int 17 = 497; int 42 = 6 * 9; String 1111 = “Totally text”;
Both newtype and the single-constructor data introduce a single value constructor, but the value constructor introduced by newtype is strict and the value constructor introduced by data is lazy. So if you have data D = D Int newtype N = N Int Then N undefined is equivalent to undefined and causes an error when … Read more
Two things: Generally, Java has just 2 levels of scope: global and function. But, try/catch is an exception (no pun intended). When an exception is thrown and the exception object gets a variable assigned to it, that object variable is only available within the “catch” section and is destroyed as soon as the catch completes. … Read more
Deep insights appreciated. I shall do my best. As other answers have noted, what’s going on here is the compiler is detecting that an expression is being used as a statement. In many languages — C, JavaScript, and many others — it is perfectly legal to use an expression as a statement. 2 + 2; … Read more
As mark said, the types are not reifiable, which is a problem in the following case: try { doSomeStuff(); } catch (SomeException<Integer> e) { // ignore that } catch (SomeException<String> e) { crashAndBurn() } Both SomeException<Integer> and SomeException<String> are erased to the same type, there is no way for the JVM to distinguish the exception … Read more
Basically it means “nothing” or “no type” There are 3 basic ways that void is used: Function argument: int myFunc(void) — the function takes nothing. Function return value: void myFunc(int) — the function returns nothing Generic data pointer: void* data — ‘data’ is a pointer to data of unknown type, and cannot be dereferenced Note: … Read more
In Lua 5.2 the best workaround is to use goto: — prints odd numbers in [|1,10|] for i=1,10 do if i % 2 == 0 then goto continue end print(i) ::continue:: end This is supported in LuaJIT since version 2.0.1
It’s not a stupid question. It’s an excellent question. As already answered the short answer is, “Another language.” Well that leads to some interesting questions? What if its the very first language written for your particular piece of hardware? A very real problem for people who work on embedded devices. As already answered “a language … Read more
Because interfaces specify only what the class is doing, not how it is doing it. The problem with multiple inheritance is that two classes may define different ways of doing the same thing, and the subclass can’t choose which one to pick.
Python’s mostly implementing a pragmatically tinged flavor of command-query separation: mutators return None (with pragmatically induced exceptions such as pop😉 so they can’t possibly be confused with accessors (and in the same vein, assignment is not an expression, the statement-expression separation is there, and so forth). That doesn’t mean there aren’t a lot of ways … Read more