syntax

Is there a way to span long method names across multiple lines?

We're using very descriptive test names for work and it's getting very annoying to horizontally scroll across them. Is there a way to get a method name to span multiple lines in C#? Something like: MyMethodNameIsReallyLong _SoImMakingItSpanMultipleLines _SoIDontHaveToHorizontallyScroll _AndMyLifeIsMuchEasier() { DoSome...

Construct an ArrayList of strings in Java as simple as one can in Javascript

In JavaScript I can build an Array of string values like: var stuff = new Array('foo','bar','baz','boz','gaz','goz'); or even easier var stuff = 'foo,bar,baz,boz,gaz,goz'.split(','); In Java it seems overly verbose and complex... is there an easier way than this? ArrayList<String> stuff = new ArrayList<String>(); stuff.add("foo");...

Is there a more Pythonic way of changing `None` to `[]` than...

Is there a more Pythonic way of doing this?: if self.name2info[name]['prereqs'] is None: self.name2info[name]['prereqs'] = [] if self.name2info[name]['optionals'] is None: self.name2info[name]['optionals'] = [] The reason I do this is because I need to iterate over those later. T...

What's the name of this Scala infix syntax for specifying type params?

I noticed this interesting syntax the other day for specifying the type parameters for a Scala class. scala> class X[T, U] defined class X scala> new (Int X Int) res1: X[Int,Int] = X@856447 Is there a name for this sort of syntax? What's a good use case for it? ...

C#: Create and pass variable straight in the method call

enter code hereI would like to know how to declare new variable straight in the parameter brackets and pass it on like this: MethodA(new int[]) //but how to fill the array if declared here? E.g. how to declare and set string? MethodA(int[] Array) ... and what if need to declare an object (class with constructor parameter)? Still pos...

What does this PHP syntax mean ?

Consider the code: $a = "foobar"; echo $a{3}; // prints b I know $a[3] is 'b' but how come using {} in place of [] produec the same result ? ...

What's the meaning of '@' in python code?

Reading some Python (PyQt) code, I came across as follows. @pyqtSignature("QString") def on_findLineEdit_textEdited(self, text): self.__index = 0 self.updateUi() How does this @pyqtSignature work? How Python treat this @? ...

Reasons for inconsistent VB.NET syntax?

Does anyone know if there's any particular reason that VB.NET construct syntax isn't consistent? For example: If ... End If Select ... End Select You'd assume it would be for... end for, while... end while ... but instead we have: While ... Wend For ... Next This has mildly frustrated me for a while, and I just got to wondering w...

Easy SQL Select Case When Statement throwing an incorrect syntax error and I can't find it!

Thank you to everyone who tries to help! I have 2 case select statements and I get the error on this statement: Center, Case Center When 'Concord Call Center' Then 'CCC' When 'Livermore Call Center' Then 'LCC' When 'Morgan Hill Call Center' Then 'MHCC' When 'Natomas Call Center' Then 'NCC' When 'Virtual Call Center' Then 'VCC' Else Cen...

What does this type of function mean in javascript?

In the below, I'm confused by the syntax (function (h,j) { }) What does it mean in javascript to have a function sit inside ()'s like that? function myfunc(c, b) { try { (function (h, j) { //do a bunch of stuff }) } catch (e) { myerror(e) } }; ...

Unknown Python Syntax

Hi I've found the following syntax in a python file: units = ( (100, 1 << 30, _('%.0f GB')), (10, 1 << 30, _('%.1f GB')), (1, 1 << 30, _('%.2f GB')), (100, 1 << 20, _('%.0f MB')), (10, 1 << 20, _('%.1f MB')), (1, 1 << 20, _('%.2f MB')), (100, 1 << 10, _('%.0f KB')), (10, ...

Is there any way to use C# methods directly as delegates?

This is more of a C# syntax question rather than an actual problem that needs solving. Say I have a method that takes a delegate as parameter. Let's say I have the following methods defined: void TakeSomeDelegates(Action<int> action, Func<float, Foo, Bar, string> func) { // Do something exciting } void FirstAction(int arg) { /* som...

function to return index of largest neighbor

F# function Problem: given a list of items e.g.: ["5";"10";"2";"53";"4"] and a Search Index, I require a function such that it compares the current given index against its neighbor, returning the largest index Example: Given Index 1 will return Index value 2 (because 10 is greater than 5). Given Index 4 will return Index 4 (beca...

Beginner syntax issues

SO has frozen for the nth time now trying to ask this question, so third time is a charm? I'm trying to write a rubyish solution to problem 6 in Project Euler, because I have the propensity to write C in other languages. However, this code: sqrsum, sumsqr = 0, 0 (1..100).each { |x| sqrsum, sumsqr += x, x**2 } p (sumsqr - (sqrsum ** 2)) ...

SQL - condition on field value?

Hi, I would like to know whether I can test some value against a condition in each returned row somehow in the query? e.g.: I have columns: X Y Z -1 1 2 2 2 -1 3 -1 3 I want to use avg() for all values except for -1. I CANNOT use where<> -1 as each row contains it once. ...

matching (and binding) two exception classes in one case statement in scala 2.7?

I have the following code: try { < ... some JSON parsing code .. > } catch { case e:ClassCastException => throw new ParseException(body, e) case e:JSONException => throw new ParseException(body, e) } This seems overly repetitious. I tried: case e:ClassCastException | e:JSONException => thr...

DB2 error on TSQL using complex case statement

I am receiving the error SQL0104N An unexpected token "," was found following "select .loan_number". Expected tokens may include: "". SQLSTATE=42601 IF OBJECT_ID('tempdb..#Temp1') is not null begin drop table #Temp1 select * into #Temp1 from openquery(LnkServer, ' Select X.loan_number, X.ls_code, x.ls_actual_completion_date x.ls_...

Dynamic let List Destructuring in Clojure

I have a let statement in which I would like to dynamically destructure a list. The following is my solution: symList ;; list of some Strings which will become the vector of Symbols to assign to valList ;; list of some values, same length as symList (let [(map read-string symList) valList] ...) An example value of symList would b...

Misbehaving Case Statement

I'm messing around in Ruby some more. I have a file containing a class with two methods and the following code: if __FILE__ == $0 seq = NumericSequence.new puts "\n1. Fibonacci Sequence" puts "\n2. Pascal\'s Triangle" puts "\nEnter your selection: " choice = gets puts "\nExcellent choice." choice = case when 1 put...

Should I use an else when an if contains a return?

I am following some examples in the book, and I noticed two different conventions for having various return conditions. Is there any difference between the two? //example 1 if(someCondition) { return (someValue); } return (someOtherValue); //example 2 if(someCondition) { return (someValue); } else { return (someOtherValue); } ...