language-design

Why is it useful to access static members “through” inherited types?

核能气质少年 提交于 2019-12-30 01:03:09
问题 I'm glad C# doesn't let you access static members 'as though' they were instance members. This avoids a common bug in Java: Thread t = new Thread(..); t.sleep(..); //Probably doesn't do what the programmer intended. On the other hand, it does let you access static members 'through' derived types. Other than operators (where it saves you from writing casts), I can't think of any cases where this is actually helpful. In fact, it actively encourages mistakes such as: // Nasty surprises ahead -

Why doesn't C# support const on a class / method level?

自古美人都是妖i 提交于 2019-12-29 19:48:04
问题 I've been wondering for a while why C# doesn't support const on a class or a method level. I know that Jon Skeet have wanted support for immutability for a long time, and I recon that using the C++ syntax of function const could aid in that. By adding a const keyword on a class level we would have total support. Now, my question is, what the reason is for the C# team to not have developed this kind of support? I'd imagine everything could be created with a compile-time check or through

Why doesn't C# support const on a class / method level?

谁说我不能喝 提交于 2019-12-29 19:47:28
问题 I've been wondering for a while why C# doesn't support const on a class or a method level. I know that Jon Skeet have wanted support for immutability for a long time, and I recon that using the C++ syntax of function const could aid in that. By adding a const keyword on a class level we would have total support. Now, my question is, what the reason is for the C# team to not have developed this kind of support? I'd imagine everything could be created with a compile-time check or through

Lua operators, why isn't +=, -= and so on defined?

非 Y 不嫁゛ 提交于 2019-12-29 04:28:09
问题 This is a question I've been mildly irritated about for some time and just never got around to search the answer to. However I thought I might at least ask the question and perhaps someone can explain. Basically many languages I've worked in utilize syntactic sugar to write (using syntax from C++): int main() { int a = 2; a += 3; // a=a+3 } while in lua the += is not defined, so I would have to write a=a+3 , which again is all about syntactical sugar. when using a more "meaningful" variable

C99 - why are false and true defined as 0 and 1 and not as ((bool)0) and ((bool)1)?

牧云@^-^@ 提交于 2019-12-29 01:38:13
问题 Just stumbled across an assert, that failed, as it compared false to the returntype of a function, as the function itself returned a bool and the assert checked not only the value, but also the type of the returnvalue to match the one of false, to guarantee, that a bool is returned. Now the problem is, that C99 defines bool as _Bool and _Bool is even not necessarily same size as int (in fact, in my experience, on most platforms in nowadays it is often same size as unsigned char), not to talk

Why does Ruby's 'gets' includes the closing newline?

梦想与她 提交于 2019-12-28 16:44:13
问题 I never need the ending newline I get from gets . Half of the time I forget to chomp it and it is a pain in the.... Why is it there? 回答1: Like puts (which sounds similar), it is designed to work with lines, using the \n character. gets takes an optional argument that is used for "splitting" the input (or "just reading till it arrives). It defaults to the special global variable $/ , which contains a \n by default. gets is a pretty generic method for readings streams and includes this

Is “monkey patching” really that bad? [closed]

馋奶兔 提交于 2019-12-28 09:18:30
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 7 months ago . Some languages like Ruby and JavaScript have open classes which allow you to modify interfaces of even core classes like numbers, strings, arrays, etc. Obviously doing so could confuse others who are familiar with the API but is there a good reason to avoid it otherwise,

Creating your own language

爱⌒轻易说出口 提交于 2019-12-28 03:38:24
问题 If I were looking to create my own language are there any tools that would help me along? I have heard of yacc but I'm wondering how I would implement features that I want in the language. 回答1: The first tool I would recommend is the Dragon Book. That is the reference for building compilers. Designing a language is no easy task, implementing it is even more difficult. The dragon book helps there. The book even reference to the standard unix tools lex and yacc. The gnu equivalent tools are

Why can't your switch statement data type be long, Java?

青春壹個敷衍的年華 提交于 2019-12-28 03:31:17
问题 Here's an excerpt from Sun's Java tutorials: A switch works with the byte , short , char , and int primitive data types. It also works with enumerated types (discussed in Classes and Inheritance) and a few special classes that "wrap" certain primitive types: Character , Byte , Short , and Integer (discussed in Simple Data Objects). There must be a good reason why the long primitive data type is not allowed. Anyone know what it is? 回答1: I think to some extent it was probably an arbitrary

Namespace Specification In Absence of Ambuguity

泪湿孤枕 提交于 2019-12-24 07:10:11
问题 Why do some languages, like C++ and Python, require the namespace of an object be specified even when no ambiguity exists? I understand that there are backdoors to this, like using namespace x in C++, or from x import * in Python. However, I can't understand the rationale behind not wanting the language to just "do the right thing" when only one accessible namespace contains a given identifier and no ambiguity exists. To me it's just unnecessary verbosity and a violation of DRY, since you're