language-design

Why do we have to name interface method parameters?

人盡茶涼 提交于 2019-12-01 02:14:11
In C# we have to name the parameters of a method of an interface. I understand that even if we didn't have to, doing so would help a reader understand the meaning, however in some cases it's not really needed: interface IRenderable { void Render(GameTime); } I would say the above is as readable and meaningful as the below: interface IRenderable { void Render(GameTime gameTime); } Is there some technical reason why names for parameters of methods on an interface are required? It's worth noting that the implementation of the interface method can use different names to those in the interface's

Why can't an interface implementation return a more specific type?

為{幸葍}努か 提交于 2019-12-01 02:05:49
If an interface specifies a property or method to return another interface, why is it not allowed for implementations of the first interface to "change" the return type into a more specific type? Let's take an example to illustrate: interface IFoo { IBar GetBar(); } interface IBar { } class Foo : IFoo { // This is illegal, we are not implementing IFoo properly public Bar GetBar() { return new Bar(); } } class Bar : IBar { } I know how to make it work, that's not my concern. I can just either: Change return type of GetFoo() to IBar , or Explicitly implement the interface and just call GetBar

Is scala.Singleton pure compiler fiction?

孤街浪徒 提交于 2019-12-01 01:50:07
问题 The Scala Language Specification says under §3.2.1: A stable type is either a singleton type or a type which is declared to be a subtype of trait scala.Singleton. I couldn't find scala.Singleton neither in the sources, in ScalaDoc nor in the binary jar file. Trying on the REPL results in: scala> class Foo extends Singleton <console>:9: error: illegal inheritance from final trait Singleton class Foo extends Singleton ^ <console>:9: error: illegal inheritance; superclass Any is not a subclass

Any reason for having “val capacity : Int” instead of “val Int Capacity” in Scala

余生长醉 提交于 2019-12-01 01:12:31
问题 I am reading Scala and I am wondering ... Why val capacity : Int instead of val Int capacity. Any reason why this choice was made. If not, it does not seem to me like a good choice to move away from the Java way of declaring it. Would have made the transition from Java to Scala easier (not by much, but little bit) 回答1: Because the majority of the time you can leave off the Int part. Scala has a much neater system of type inference than Java does. 回答2: I think I read a statement by Martin

Why can't an interface implementation return a more specific type?

谁都会走 提交于 2019-11-30 21:26:03
问题 If an interface specifies a property or method to return another interface, why is it not allowed for implementations of the first interface to "change" the return type into a more specific type? Let's take an example to illustrate: interface IFoo { IBar GetBar(); } interface IBar { } class Foo : IFoo { // This is illegal, we are not implementing IFoo properly public Bar GetBar() { return new Bar(); } } class Bar : IBar { } I know how to make it work, that's not my concern. I can just either:

Methodologies for designing a simple programming language

余生颓废 提交于 2019-11-30 21:21:05
In my ongoing effort to quench my undying thirst for more programming knowledge I have come up with the idea of attempting to write a (at least for now) simple programming language that compiles into bytecode. The problem is I don't know the first thing about language design. Does anyone have any advice on a methodology to build a parser and what the basic features every language should have? What reading would you recommend for language design? How high level should I be shooting for? Is it unrealistic to hope to be able to include a feature to allow one to inline bytecode in a way similar to

Why doesn't ORACLE allow consecutive newline characters in commands?

走远了吗. 提交于 2019-11-30 19:58:25
I write: :CREATE TABLE Person ( :name CHAR(10), : :ssn INTEGER); and save it to a file "a.sql" (colon represents beginning of line, is not in actual code.) If I then run it by typing "@a" in the SQL*Plus command prompt, it will tell me that the line starting with "ssn" is not recognized as a command, and is ignored. From what I gather, it seems that sqlplus terminates a command if it encounters multiple newline characters in a row. Is this an accurate statement? If so, does anyone know if this is necessary/ why it chooses to do this? I don't know about the why, but a completely blank line

Why can't we create an instance of an abstract class?

早过忘川 提交于 2019-11-30 19:07:57
I found in many places that : An Abstract Class is a class which is supposed to be used as a base class. An Abstract Class is a class which has atleast one Pure Virtual Function. But one thing that always strikes my mind is why can't we create an instance of an abstract class? Many places on the Internet say there is no point in creating an instance, or some say that they are supposed to be used as base classes. But why is it an error to create an instance of an abstract class? Your void bar()=0; is not valid -- the =0 notation can only be used with virtual functions. The whole point of an

Declarations, definitions, initializations in C, C++, C#, Java and Python [closed]

隐身守侯 提交于 2019-11-30 18:30:37
What do the terms mean in each of the above languages? Why do the languages differ (wherever they do, if at all they do) in this respect? C/C++: A declaration is a statement that says "here is the name of something and the type of thing that it is, but I'm not telling you anything more about it". A definition is a statement that says "here is the name of something and what exactly it is". For functions, this would be the function body; for global variables, this would be the translation unit in which the variable resides. An initialization is a definition where the variable is also given an

Empty if-statements [duplicate]

房东的猫 提交于 2019-11-30 17:19:08
This question already has an answer here: Semicolon at end of 'if' statement 18 answers By "empty if-statement", I mean something like this (note the semicolon): if (condition); I'm having trouble thinking of an application for this. With a while loop you can do this: while (callUntilReturnsFalse()); But there's no such application for an if-statement. What's more, the Java compiler doesn't issue an error or a warning when confronted with such a statement. This can lead to large and silent problems, especially with a long and convoluted statement: if ((functionA() && functionB(getFoo()) ||