language-features

How-to: short-circuiting inverted ternary operator implemented in, e.g. C#? Does it matter?

Suppose you are using the ternary operator, or the null coalescing operator, or nested if-else statements to choose assignment to an object. Now suppose that within the conditional statement, you have the evaluation of an expensive or volatile operation, requiring that you put the result into a temporary variable, capturing its state, so...

Flex : Assignment in Conditionals

If I use an Assignment within conditional, for e.g. if(userType='admin') Flex throws a warning,unlike Java, which throws an error. Why should Flex be doing this, despite being one of the newest languages? 1100: Assignment within conditional. Did you mean == instead of =? ...

Getting burned by inconsistent passed by value rules in Java (1.5), was the choice of int [] just syntactic sugar to make array objects look like C/C++ arrays?

I read something online that incorrectly stated that standard int [], etc arrays in Java were passed as copies, rather than passing references to the arrays, in analogy with the basic numerical types, and ended up overwriting an array when I thought I was modifying a copy. Can I chalk this up as a design choice to make things simpler to ...

Programmatically setting Repeated Parameters in Scala

I'm trying to call Futures.awaitAll with a variable number of well...Futures. awaitAll is defined as awaitAll(timeout : Long, fts : Future[Any]*). I have tried passing in a List and an Array but both won't work: list = future1 :: future2 :: Nil Futures.awaitAll(1000, list) found : List[scala.actors.Future[Any]] required: scala.actors....

How can I pass my locals and access the variables directly from another function?

Let's say I have this : def a(dict): locals().update(dict) print size def b(): size = 20 f(locals()) What do I have to do to access the size variable directly from the a function? I know of : size = dict["size"] but I think there should be a more direct way. I tried using locals().update(dict) but it didn't work. Is ther...

Is JavaScript an application language?

I have always thought of JavaScript as a client-side scripting tool for augmenting the functionality of HTML, which in turn is usually generated by some other server-side technology - Java, .NET, Rails, Django, PHP, etc. Recently though I have heard people talk about JavaScript as an "application language". I understand that application...

How to prevent "fat finger syndrome" in absence of req. predeclearation?

For example: on rising edge (reset): sync = defaultValue; ... ... various processing constructs ... ... if (event == someEvent) // Back at the Batcave // The vilianous Fat finger Syndrome // strikes again! synch = someEventProcessing() ... ... various processing constructs ... ... someSyncProcessing(sync) // Foiled again!...

Scala equivalent to Haskell's where-clauses?

Is it possible to use something similar to where-clauses in Scala? Maybe there is some trick I didn't think of? Edit: Thanks for all your answers, they are very much appreciated. To sum up: Local vars, vals and defs can be used to achieve almost the same thing. For lazy evaluation, one can use lazy val (with implicit caching) or functi...

Is there a way to escape root namespace in VB?

namespace ConsoleApplication1 { class Program { static void Main(string[] args) { System.Text.MyCustom mc = new System.Text.MyCustom(); } } } namespace System.Text { public class MyCustom { } } How do I do this in VB, while having a root namespace in the application, is this possib...

Impressive examples in Java?

I'm going to teach a Java course, and I want to show some interesting and impressive examples of simple Java programs at the first lecture to awaken student interest. Except for the default examples which come with the JDK, what can you advise? What possibilities of Java were you impressed by? One more thing - students admittedly kno...

interface for only certain classes?

Can you create an interface which can only be applied to certain classes and subclasses? If my interface is only added to different subclasses of JComponent, and I need to refer to both the methods of JComponent and my interface... how should I do this? Off the top of my head I can accomplish this by adding methods from JComponent to ...

Can someone demystify the yield keyword?

I have seen the yield keyword being used quite a lot on Stack Overflow and blogs. I don't use LINQ. Can someone explain the yield keyword? I know that similar questions exist. But none really explain what is its use in plain simple language. ...

Python Critique

Hi, I'm using Python now for about two months, and to be honest, it really made me love programming again. After programming in C, Java, and worst of all, C++, Python is incredibly fun. Thinking that I approach such language with all positive bias, I would love to hear some critique of Python language. Beside its extremely rich library,...

What are the differences between VB.NET and previous versions of VB?

I'm reasonably familiar with the various forms of VB that existed prior to .NET (VB6, VBA, VBScript...), but have yet to delve into The Sweet New Flavor that is VB.NET. So I would very much appreciate it if someone would provide a quick summary of the major differences in the language brought about by VB.NET. ...

Something similar to sql IN statement within .NET framework?

I have this function: public bool IsValidProduct(int productTypeId) { bool isValid = false; if (productTypeId == 10 || productTypeId == 11 || productTypeId == 12) { isValid = true; } return isValid; } but I'm wondering if there's an easier way to...

Poll: What is stopping you from switching (from Java) to Scala ?

What would make you to switch to Scala ? If you are negative on the switching to Scala, please state the reason as well (or upvote). As with all StackOverflow Poll type Q&As, please make certain your answer is NOT listed already before adding a new answer If it already exists, vote that one up so we see what the most popular answe...

What is the difference between VB and VBScript

What is the difference between VB and VBScript? ...

Why should I use Pike? And what makes it a good language?

I stumbled upon Pike and got very interested in it's structure and setup. It seems like a simplified and safer C++. (though interpreted). Though it has a small number of libraries. The ones available make it interesting to use. It is something I will definitely look at but since there was no Pike question here on SO. I thought I'd start...

Should const functionality be expanded?

EDIT: this question could probably use a more apropos title. Feel free to suggest one in the comments. In using C++ with a large class set I once came upon a situation where const became a hassle, not because of its functionality, but because it's got a very simplistic definition. Its applicability to an integer or string is obvious, ...

Why doesn't a python dict.update() return the object?

I 'm trying to do : award_dict = { "url" : "http://facebook.com", "imageurl" : "http://farm4.static.flickr.com/3431/3939267074_feb9eb19b1_o.png", "count" : 1, } def award(name, count, points, desc_string, my_size, parent) : if my_size > count : a = { "name" : name, "description" : desc_st...