syntax

scala dot syntax (or lack thereof)

I was going through the wonderful book, Programming in Scala when I came across a piece of code that just doesn't make sense to me: def above(that: Element): Element = { val this1 = this widen that.width val that1 = that widen this.width elem(this1.contents ++ that1.contents) } Note line 2 and 3: val this1 = this widen th...

No Multiline Lambda in Python: Why not?

I've heard it said that multiline lambdas can't be added in Python because they would clash syntactically with the other syntax constructs in Python. I was thinking about this on the bus today and realized I couldn't think of a single Python construct that multiline lambdas clash with. Given that I know the language pretty well, this s...

How do I concatenate variables with a string to create an Oracle table name in a FROM clause in a stored procedure?

e.g. select * from v_schema || '.tbl_a@' || abc.world ...

VB.NET 3.5; compiler complaining about nullable types (as in Double?) with "error BC30037: Character is not valid."

So, Visual studio just started throwing "error BC30037: Character is not valid." at me (while validating a web site) whenever I use the nullable operator anywhere within one of my VB.NET 3.5 projects. This happened to a colleague some months ago but he doesn't remember how he fixed (I seem to remember it fixing itself eventually). If ...

C++ method declaration question

I have some code in Image.cpp: Image::Image( int width, int height, int depth ) : m_sFileName(0) { ... } and in Image.h: class Image: public DrawAble, public RenderAble { ... private : std::string *m_sFileName; }; My question is: what is happening with m_sFilename in the first line? I guess it is set to NULL...

Ruby and Rails: Statement Modifiers in Views?

I have this code <% if approved %> <td>Flow Number</td> <% end %> and I'd like to shorten it using statement modifiers. Of course I can use <%="<td>Flow Number</td>" if approved -%> but is there a shorter way? I'd also like to get the markup out of quotes. ...

PHP: default as first option in switch statement?

I've tested this and it works fine, but it looks... weird... to me. Should I be concerned that this is nonstandard form which will be dropped in a future version of PHP, or that it may stop working? I've always had a default case as the final case, never as the first case... switch($kind) { default: // The kind wasn't valid, se...

Type-indifferent comparison in Ruby

I'm sure this is a basic question in Ruby: Is there a way to check if a == b even if a is an integer and b is a string? I realize that I can do a.to_s == b.to_s but I'd like to know if there's some other, better way. Edit: The question originally had a typo and said a.to_s and b.to_s which was edited after parsenome pointed out...

Question about some wild javascript syntax and contraints

Hey all, So I know javascript pretty well, but I'm not sure about this one. Tough to explain so I'll just show it: var view = new View(); view.rating = 4.5; Is there anyway to have view.rating be called as a function to manipulate the DOM a bit and set that rating to five? So in View: View.prototype = { rating : function() { ...

Help Meta-programming in Ruby: Overwriting Activerecord Setters

I have no idea how to "metatize" this method, but I know it should be simple. The method looks like this def check_sent=(value) Date.parse(value) rescue @dates_bad = true self.write_attribute(:check_sent, value) end This is for an ActiveRecord subclass. I would like to have these methods for all fields that I specify....

How do predicate parameters work syntactically in C# ?

Some Object Relational Mapping (ORM) frameworks (such as LLBLGen) allow you to specify "predicate" parameters to the query methods, such as (simplified a bit): var entities = adapter.FetchEntities(EntityType.Employee, EmployeeFields.Salary > 50000); How does that 2nd parameter work syntactically in C#? It kind of looks like a lam...

mySQL - results per number of seconds.

Hello, Im trying to work out (and failing) how I can get the number of sessions (just using that term generically, dont worry too much) per second. I.e. im looking for retention. I have a table that is updated periodically with the number of seconds that a session is active. I want to get a list of:- MAX(`time) - i.e. the highest numb...

Use composite select items in where clause

This question is best phrased with a simple example. Why can't I do this? select (lastname + ', ' + firstname) as fullname from people where fullname = 'Bloggs, Joe' instead I have to do this: select (lastname + ', ' + firstname) as fullname from people where (lastname + ', ' + firstname) = 'Bloggs, Joe' which smells bad to me. T...

Is there a shortcut in ColdFusion for converting undefined value to empty string?

I find myself writing code like this in ColdFusion a lot: <cfset inputval = "" /> <cfif IsDefined("Form.Releases")> <cfset inputval = Form.Releases /> </cfif> This is very cumbersome. I just want an undefined value to be converted to an empty string. Is there any kind of shortcut? For example, in PHP I do this with strval funct...

SQL: Insert all records from one table to another table without specific the columns

I want to insert all the record from the back up table foo_bk into foo table without specific the columns. if i try this query INSERT INTO foo SELECT * FROM foo_bk i'll get error "Insert Error: Column name or number of supplied values does not match table definition." Is it possible to do bulk insert from one table to another witho...

Ruby: The Meta-class and Class Variables

I've been looking at some articles that say that class variables are bad in Ruby. They suggest using the meta-class (or singleton class). This is my sample code class Joe class << self # here we're putting methods in Joe's "meta class" attr_accessor :foo end def self.foo2 end def self.foo2=value end end puts Joe.single...

What is the syntax to force the use of an index for a join in MySQL

The use of the "FORCE/USE/IGNORE INDEX" when doing a straightforward select is well-documented, but it's not clear from the documentation how to do it for a JOIN. How do you force a specific index to be used for a joined table? ...

variables inside variables

Ok this might sound like a dumb question but bear with me. I am trying to make it so that when people go to example.php?id=1, example.php?id=2, example.php?id=3 etc they see different data called from an included file filling in the blanks. I have a variable called $offername and I want to display $offer1name, $offer2name, $offer3name...

Is there a wiki processor for Trac to format and colour Python tracebacks?

Understandably many of the tickets we file in Trac contain tracebacks. It would be excellent if these were nicely formatted and syntax highlighted. I've conducted a cursory Google search for a Python traceback wiki processor and have not found any quick hits. I'm happy to roll my own if anyone can recommend a traceback formatter (stand...

Can I lock(something) on one line in C#?

Will the _otherThing field below be protected by the locks? class ThreadSafeThing { private readonly object _sync = new object(); private SomeOtherThing _otherThing; public SomeOtherThing OtherThing { get { lock(_sync) return _otherThing; } } public void UpdateOtherThing(SomeOtherThing otherThing) { lock(_...