syntax

Can you add new statements to Python's syntax?

Can you add new statements (like print, raise, with) to Python's syntax? Say, to allow.. mystatement "Something" Or, new_if True: print "example" Not so much if you should, but rather if it's possible (short of modifying the python interpreters code) ...

What is the purpose of the colon before a block in Python?

What is the purpose of the colon before a block in Python? Example: if n == 0: print "The end" ...

What does using a dollar sign after $this-> in PHP mean?

I'm a little confused by some PHP syntax I've come across. Here is an example: $k = $this->_tbl_key; if( $this->$k) { $ret = $this->_db->updateObject( $this->_tbl, $this, $this->_tbl_key, $updateNulls ); } else { $ret = $this->_db->insertObject( $this->_tbl, $this, $this->_tbl_key ); } My question is basically what does $this...

Does Ruby support verbatim strings?

Is there support in Ruby for (for lack of a better word) non-escaped (verbatim) strings? Like in C#: @"c:\Program Files\" ...or in Tcl: {c:\Program Files\} ...

What does the plus sign do in 'return +new Date'

I've seen this in a few places function(){ return +new Date; } And I can see that it is returning a timestamp rather than a date object, but I can't find any documentation on what the plus sign is doing. Can anyone explain? ...

How do I pass multiple parameters to a logparser sql query?

Using logparser you can pass on parameters to the query you'd like to run such as: logparser file:query.sql?logs=somewhere\*.log -o:Sql -server:databaseserver -database:database -createtable:ON -i:IISW3C -iCheckPoint:somewhere\query.lpc -transactionRowCount:200 Now I want to pass a second parameter to the sql query but it doesn...

C++ example of Coding Horror or Brilliant Idea?

At a previous employer, we were writing binary messages that had to go "over the wire" to other computers. Each message had a standard header something like: class Header { int type; int payloadLength; }; All of the data was contiguous (header, immediately followed by data). We wanted to get to the payload given that we had ...

What's the syntax for variables in an MSSQL stored procedure?

I have a simple query like this: select * from mytable where id > 8 I want to make the 8 a variable. There's some syntax like declare @myvar int myvar = 8 but I don't know the exact syntax. What is it? Thanks! ...

History of VB.NET Nullable syntax

I can't find a definitive answer. Since C# 2.0 you've been able to declare int? i = 125; as shorthand for Nullable<int> i = Nullable<int>(123); I recall reading somewhere that VB.NET did not allow this shortcut. But low and behold, I tried it in VS 2008 today and it works. Does anyone know whether it's been this way since .NET 2...

Avoiding Mixup of Language Details

Today someone asked me what was wrong with their source code. It was obvious. "Use double equals in place of that single equal in that if statement. Um, i think..." As i remember some languages actually take a single equals for comparison. Since i sometimes forget or mix up the syntax details among the several languages i use, i step...

Double cast for Double smaller than zero

Double out = otherTypes.someMethod(c, c2); assertEquals((Double)-1.0D, out); I get error "Double cannot be resolved" (the Double in assertEquals), is there any way to hack around it except extracting variable? Is this bug in Java or just very usefull feature that wont be fix? ...

A "regex for words" (semantic replacement) - any example syntax and libraries?

I'm looking for syntatic examples or common techniques for doing regular expression style transformations on words instead of characters, given a procedural language. For example, to trace copying, one would want to create a document with similar meaning but with different word choices. I'd like to be able to concisely define these po...

Closures in Java 7

I have heard that closures could be introduced in the next Java standard that is scheduled to be released somewhere around next summer. What would this syntax look like? I read somewhere that introducing closures in java is a bigger change than generic was in java 5. Is this true? pros and cons? (By now we definitely know that closur...

What do curly braces by themselves mean in java?

for example, I have the following code (generated, not written) if(node.getId() != null) { node.getId().apply(this); } { List<PExp> copy = new ArrayList<PExp>(node.getArgs()); for(PExp e : copy) { e.apply(this); } } outAMethodExp(node); What do those extra curly...

When did single quotes in HTML become so popular?

Recently I've been seeing a lot of this: <a href='http://widget-site-example.com/example.html'&gt; <img src='http://widget-site-example.com/ross.jpg' alt='Ross&#39;s Widget' /> </a> Is it even valid to use single quotes in HTML? As I've highlighted above it's also problematic because you have to escape apostrophes. ...

What do parentheses in a C variable declaration mean?

Can someone explain what this means? int (*data[2])[2]; ...

Lisp DO variable syntax reasoning

In Peter Seibel's Practical Common Lisp, he gives this example: (do ((nums nil) (i 1 (1+ i))) ((> i 10) (nreverse nums)) (push i nums)) I can see how it works, using nums inside the loop but not giving it a step-form. Why would you put nums in the variable-definition rather than do this: (let (nums) (do ((i 1 (+ i 1))) ...

auto c/c++

Has anyone ever seen the storage class auto explicitly in use in c/c++? If so, in what situation? ...

In javascript, can I override the brackets to access characters in a string?

Is there some way I can define String[int] to avoid using String.CharAt(int)? ...

Syntax for putting a block on a single line

So I've got a Ruby method like this: def something(variable, &block) .... end And I want to call it like this: something 'hello' { do_it } Except that isn't working for me, I'm getting a syntax error. If I do this instead, it works: something 'hello' do do_it end Except there I'm kind of missing the nice look of it being on ...