C# syntax quiz [modified*2]
-
If you have a valid C# program (valid=compiles without errors), can the removal of a space between two non-keyword operators cause the program to no longer compile / behave differently? (behave different is solved by Rama Krishna Vavilala and PIEBALDconsult - now try to break compilation without using unary operators) E.g. removing the space between "< =" changes it from two tokens into the combined "<=" token that has different meaning. But this is not a solution to the question because there is no valid C# program that contains "< =". Is there a combination of two non-keyword non-identifier tokens that is makes a valid program with a space in between but breaks when you remove the space?
Last modified: 26mins after originally posted --
-
If you have a valid C# program (valid=compiles without errors), can the removal of a space between two non-keyword operators cause the program to no longer compile / behave differently? (behave different is solved by Rama Krishna Vavilala and PIEBALDconsult - now try to break compilation without using unary operators) E.g. removing the space between "< =" changes it from two tokens into the combined "<=" token that has different meaning. But this is not a solution to the question because there is no valid C# program that contains "< =". Is there a combination of two non-keyword non-identifier tokens that is makes a valid program with a space in between but breaks when you remove the space?
Last modified: 26mins after originally posted --
Dang, I think I've seen this one before, I'm pretty sure the answer is "yes", but I don't remember what the syntax is.
-
If you have a valid C# program (valid=compiles without errors), can the removal of a space between two non-keyword operators cause the program to no longer compile / behave differently? (behave different is solved by Rama Krishna Vavilala and PIEBALDconsult - now try to break compilation without using unary operators) E.g. removing the space between "< =" changes it from two tokens into the combined "<=" token that has different meaning. But this is not a solution to the question because there is no valid C# program that contains "< =". Is there a combination of two non-keyword non-identifier tokens that is makes a valid program with a space in between but breaks when you remove the space?
Last modified: 26mins after originally posted --
string abc = "\u12 345";
File Not Found
-
If you have a valid C# program (valid=compiles without errors), can the removal of a space between two non-keyword operators cause the program to no longer compile / behave differently? (behave different is solved by Rama Krishna Vavilala and PIEBALDconsult - now try to break compilation without using unary operators) E.g. removing the space between "< =" changes it from two tokens into the combined "<=" token that has different meaning. But this is not a solution to the question because there is no valid C# program that contains "< =". Is there a combination of two non-keyword non-identifier tokens that is makes a valid program with a space in between but breaks when you remove the space?
Last modified: 26mins after originally posted --
How about this:
int i = 0;
int j = 1;
i =+ +j;Space i = 1, Remove the space i = 2.
Co-Author ASP.NET AJAX in Action
-
If you have a valid C# program (valid=compiles without errors), can the removal of a space between two non-keyword operators cause the program to no longer compile / behave differently? (behave different is solved by Rama Krishna Vavilala and PIEBALDconsult - now try to break compilation without using unary operators) E.g. removing the space between "< =" changes it from two tokens into the combined "<=" token that has different meaning. But this is not a solution to the question because there is no valid C# program that contains "< =". Is there a combination of two non-keyword non-identifier tokens that is makes a valid program with a space in between but breaks when you remove the space?
Last modified: 26mins after originally posted --
x = y - -5 ; x = y --5 ;
-
string abc = "\u12 345";
File Not Found
"\u12 345" is a single string literal token; removing the space changes the string value but does not combine any tokens. I'm looking for something that combined produces an operator.
-
How about this:
int i = 0;
int j = 1;
i =+ +j;Space i = 1, Remove the space i = 2.
Co-Author ASP.NET AJAX in Action
Correct. I was looking for a different solution, try something that doesn't use unary operators.
-
If you have a valid C# program (valid=compiles without errors), can the removal of a space between two non-keyword operators cause the program to no longer compile / behave differently? (behave different is solved by Rama Krishna Vavilala and PIEBALDconsult - now try to break compilation without using unary operators) E.g. removing the space between "< =" changes it from two tokens into the combined "<=" token that has different meaning. But this is not a solution to the question because there is no valid C# program that contains "< =". Is there a combination of two non-keyword non-identifier tokens that is makes a valid program with a space in between but breaks when you remove the space?
Last modified: 26mins after originally posted --
public class Foo{ public static void SomeMethod(){ Foo bar; } }
File Not Found
-
If you have a valid C# program (valid=compiles without errors), can the removal of a space between two non-keyword operators cause the program to no longer compile / behave differently? (behave different is solved by Rama Krishna Vavilala and PIEBALDconsult - now try to break compilation without using unary operators) E.g. removing the space between "< =" changes it from two tokens into the combined "<=" token that has different meaning. But this is not a solution to the question because there is no valid C# program that contains "< =". Is there a combination of two non-keyword non-identifier tokens that is makes a valid program with a space in between but breaks when you remove the space?
Last modified: 26mins after originally posted --
while (0 = = 0) { Foobie; }
God Bless, Jason
God doesn't believe in atheist but He still loves them. -
public class Foo{ public static void SomeMethod(){ Foo bar; } }
File Not Found
Foobar still isn't an operator. Somewhat correct because I wrote "non-keyword token" where I really meant "non-keyword non-literal non-identifier" (=operator) token.
-
while (0 = = 0) { Foobie; }
God Bless, Jason
God doesn't believe in atheist but He still loves them.The code must compile before removing the space.
-
If you have a valid C# program (valid=compiles without errors), can the removal of a space between two non-keyword operators cause the program to no longer compile / behave differently? (behave different is solved by Rama Krishna Vavilala and PIEBALDconsult - now try to break compilation without using unary operators) E.g. removing the space between "< =" changes it from two tokens into the combined "<=" token that has different meaning. But this is not a solution to the question because there is no valid C# program that contains "< =". Is there a combination of two non-keyword non-identifier tokens that is makes a valid program with a space in between but breaks when you remove the space?
Last modified: 26mins after originally posted --
csc *.cs
File Not Found
-
The code must compile before removing the space.
To compile or not compile that is the question isn't it. Let us evaluate the situation, how does you mother make you feel?:sigh:
God Bless, Jason
God doesn't believe in atheist but He still loves them. -
If you have a valid C# program (valid=compiles without errors), can the removal of a space between two non-keyword operators cause the program to no longer compile / behave differently? (behave different is solved by Rama Krishna Vavilala and PIEBALDconsult - now try to break compilation without using unary operators) E.g. removing the space between "< =" changes it from two tokens into the combined "<=" token that has different meaning. But this is not a solution to the question because there is no valid C# program that contains "< =". Is there a combination of two non-keyword non-identifier tokens that is makes a valid program with a space in between but breaks when you remove the space?
Last modified: 26mins after originally posted --
Maybe: G1<G2<int> > collection; I know that this makes trouble if you remove space between > > on some C++ compilers, and I read somewhere that they changed parser and lexer in C# to solve this problem. Ok I found the source: C# 2.0 specification, so my answer is valid only for C# 1.0 :)
Mostly, when you see programmers, they aren't doing anything. One of the attractive things about programmers is that you cannot tell whether or not they are working simply by looking at them. Very often they're sitting there seemingly drinking coffee and gossiping, or just staring into space. What the programmer is trying to do is get a handle on all the individual and unrelated ideas that are scampering around in his head. (Charles M Strauss)
-
Maybe: G1<G2<int> > collection; I know that this makes trouble if you remove space between > > on some C++ compilers, and I read somewhere that they changed parser and lexer in C# to solve this problem. Ok I found the source: C# 2.0 specification, so my answer is valid only for C# 1.0 :)
Mostly, when you see programmers, they aren't doing anything. One of the attractive things about programmers is that you cannot tell whether or not they are working simply by looking at them. Very often they're sitting there seemingly drinking coffee and gossiping, or just staring into space. What the programmer is trying to do is get a handle on all the individual and unrelated ideas that are scampering around in his head. (Charles M Strauss)
C# is not C++ - generics in C# work the same both with > > and >>. And AFAIK the next C++ standard will specify how compilers should distinguish the shift operator from two > without requiring that ugly space.
-
C# is not C++ - generics in C# work the same both with > > and >>. And AFAIK the next C++ standard will specify how compilers should distinguish the shift operator from two > without requiring that ugly space.
C# 2.0 spec:
The syntax for generics uses the < and > characters to delimit type parameters and type arguments (similar to the syntax used in C++ for templates). Constructed types sometimes nest, as in List<Nullable<int>>, but there is a subtle grammatical problem with such constructs: the lexical grammar will combine the last two characters of this construct into the single token >> (the right shift operator), rather than producing two > tokens, which the syntactic grammar would require. Although a possible solution is to put a space in between the two > characters, this is awkward and confusing, and does not add to the clarity of the program in any way.
So IMHO, as I said, C# _1.0_ had this problem.
Mostly, when you see programmers, they aren't doing anything. One of the attractive things about programmers is that you cannot tell whether or not they are working simply by looking at them. Very often they're sitting there seemingly drinking coffee and gossiping, or just staring into space. What the programmer is trying to do is get a handle on all the individual and unrelated ideas that are scampering around in his head. (Charles M Strauss)
-
C# 2.0 spec:
The syntax for generics uses the < and > characters to delimit type parameters and type arguments (similar to the syntax used in C++ for templates). Constructed types sometimes nest, as in List<Nullable<int>>, but there is a subtle grammatical problem with such constructs: the lexical grammar will combine the last two characters of this construct into the single token >> (the right shift operator), rather than producing two > tokens, which the syntactic grammar would require. Although a possible solution is to put a space in between the two > characters, this is awkward and confusing, and does not add to the clarity of the program in any way.
So IMHO, as I said, C# _1.0_ had this problem.
Mostly, when you see programmers, they aren't doing anything. One of the attractive things about programmers is that you cannot tell whether or not they are working simply by looking at them. Very often they're sitting there seemingly drinking coffee and gossiping, or just staring into space. What the programmer is trying to do is get a handle on all the individual and unrelated ideas that are scampering around in his head. (Charles M Strauss)
Those wouldn't be operators anyway would they? They're delimiters or something in that usage. -- modified at 17:25 Friday 24th August, 2007 Huh, the documentation just says " client code must declare and instantiate a constructed type by specifying a type argument inside the angle brackets. " So I guess Microsoft doesn't know what to call them anyway.
-
Those wouldn't be operators anyway would they? They're delimiters or something in that usage. -- modified at 17:25 Friday 24th August, 2007 Huh, the documentation just says " client code must declare and instantiate a constructed type by specifying a type argument inside the angle brackets. " So I guess Microsoft doesn't know what to call them anyway.
Well, I consider them operator tokens as a standalone ">" is a greater-than operator. Lexical analysis only produces tokens, what's an operator and what isn't can change based on the context they are used in - so strictly speaking there no such thing as an operator token. (that's why I wrote "non-keyword non-identifier non-literal"). "< <" is never valid, "> >" only for generics where it is the same as ">>". So those are not solutions. Hint: in the solution I'm looking for, the same character is used twice with a space in between, but the first instance has a totally different meaning than the second (only the second is a real operator). Without the space, they produce yet another operator.
-
If you have a valid C# program (valid=compiles without errors), can the removal of a space between two non-keyword operators cause the program to no longer compile / behave differently? (behave different is solved by Rama Krishna Vavilala and PIEBALDconsult - now try to break compilation without using unary operators) E.g. removing the space between "< =" changes it from two tokens into the combined "<=" token that has different meaning. But this is not a solution to the question because there is no valid C# program that contains "< =". Is there a combination of two non-keyword non-identifier tokens that is makes a valid program with a space in between but breaks when you remove the space?
Last modified: 26mins after originally posted --
It's easy with unary plus/minus <-> increment/decrement:
i =+ +j;
x = y - -5 ;But there is another solution that's much more difficult to find:
object o = null;
string text = o is int ? ? "o is Nullable" : "o is not Nullable";Removing the space between the question marks causes them to become the null-coalescing operator ??, and you get a syntax error at the ':'.
-
It's easy with unary plus/minus <-> increment/decrement:
i =+ +j;
x = y - -5 ;But there is another solution that's much more difficult to find:
object o = null;
string text = o is int ? ? "o is Nullable" : "o is not Nullable";Removing the space between the question marks causes them to become the null-coalescing operator ??, and you get a syntax error at the ':'.
Daniel Grunwald wrote:
i =+ +j;
What's that? It's not +=