language-design

Using flag to identify spoken language

笑着哭i 提交于 2019-12-23 21:48:50
问题 In the webapp I am doing, I need to identify language people are speaking. I wanted to use flag to do that. But I have some problems. For example, if you speak French, you can put the French flag. But if you speak English you can put either the US or UK flag or a mix of both. Which flag to choose for Arabic language ? Saudi Arabian flag ? Algeria ? Morocco ? 回答1: I think it's usual to use fragments of the language as a kind of graphic (text, instead of flags), for example: english français

Why is the classic ASP server-side include enclosed in a comment?

大憨熊 提交于 2019-12-23 20:15:31
问题 Why is the syntax for server-side inclusion <!--#include file="suchandsuch"--> ? Placing semantically meaningful content inside a comment seems awkward and misleading – indeed, the first time I saw this syntax, I assumed it was an include that had been "commented out". What was the reasoning behind designing the language to use this syntax, as opposed to alternatives like <% #include file="suchandsuch" %> ? (I'm aware that parsing that example alternative with simple substitution would render

Operator '??' cannot be applied to operands of type for child classes

↘锁芯ラ 提交于 2019-12-23 15:22:45
问题 The following code gives the error in the title on the second line in the Main function. public class P {} public class B : P {} public class A : P {} void Main() { P p = GetA()??GetB(); } public A GetA() { return new A(); } public B GetB() { return new B(); } A simple tweak to the line like these p = (P)GetA()??GetB(); or p = GetA()??(P)GetB(); works. I'm curious why the compiler doesn't understand that both are child classes of the left hand side container and allow the operation without

Reflection: Why are there methods like setAccessible()?

喜你入骨 提交于 2019-12-23 12:39:01
问题 Just wondering, why did the people who invented Java write methods like setAccessible(boolean flag) , which makes the access-modifiers (specially private) useless and cannot protect fields, methods, and constructors from being reached? Look at the following simple example: public class BankAccount { private double balance = 100.0; public boolean withdrawCash(double cash) { if(cash <= balance) { balance -= cash; System.out.println("You have withdrawn " + cash + " dollars! The new balance is: "

Why was no intrinsic access to the CPU's status register in the design of both C and C++?

孤街浪徒 提交于 2019-12-23 09:38:17
问题 In the case of the overflow flag, it would seem that access to this flag would be a great boon to cross-architecture programming. It would provide a safe alternative to relying on undefined behaviour to check for signed integer overflow such as: if(a < a + 100) //detect overflow I do understand that there are safe alternatives such as: if(a > (INT_MAX - 100)) //detected overflow However, it would seem that access to the status register or the individual flags within it is missing from both

Java Language Design with toString

早过忘川 提交于 2019-12-23 07:32:23
问题 We did they make the decision to not implement a toString method for int[] , but instead let it inherit the toString method from Object ? 回答1: They did implement more reasonable toString methods for arrays. They are located in the java.util.Arrays class. As for reasoning. I'm assuming by the overrides provided in the Arrays class, that trying to implement a generic toString for different types of arrays is either complex or impossible. The toString method would have to know what type of array

Java Language Design with toString

独自空忆成欢 提交于 2019-12-23 07:32:10
问题 We did they make the decision to not implement a toString method for int[] , but instead let it inherit the toString method from Object ? 回答1: They did implement more reasonable toString methods for arrays. They are located in the java.util.Arrays class. As for reasoning. I'm assuming by the overrides provided in the Arrays class, that trying to implement a generic toString for different types of arrays is either complex or impossible. The toString method would have to know what type of array

Implicit conversion from char to single character string

风格不统一 提交于 2019-12-23 07:25:40
问题 First of all: I know how to work around this issue. I'm not searching for a solution. I am interested in the reasoning behind the design choices that led to some implicit conversions and didn't lead to others. Today I came across a small but influential error in our code base, where an int constant was initialised with a char representation of that same number. This results in an ASCII conversion of the char to an int . Something like this: char a = 'a'; int z = a; Console.WriteLine(z); //

Implicit conversion from char to single character string

烂漫一生 提交于 2019-12-23 07:25:05
问题 First of all: I know how to work around this issue. I'm not searching for a solution. I am interested in the reasoning behind the design choices that led to some implicit conversions and didn't lead to others. Today I came across a small but influential error in our code base, where an int constant was initialised with a char representation of that same number. This results in an ASCII conversion of the char to an int . Something like this: char a = 'a'; int z = a; Console.WriteLine(z); //

Why doesn't Python allow referencing a class inside its definition?

橙三吉。 提交于 2019-12-23 05:09:01
问题 Python (3 and 2) doesn't allow you to reference a class inside its body (except in methods): class A: static_attribute = A() This raises a NameError in the second line because 'A' is not defined , while this class A: def method(self): return A('argument') works fine. In other languages, for example Java, the former is no problem and it is advantageous in many situations, like implementing singletons. Why isn't this possible in Python? What are the reasons for this decision? EDIT: I edited my