A language feature is a distinct aspect of a programming language, such as binding rules, lexical design, or facets of the type system.
Questions tagged [language-features]
618 questions
1719
votes
8 answers
How to loop through all enum values in C#?
This question already has an answer here:
How do I enumerate an enum in C#? 26 answers
public enum Foos
{
A,
B,
C
}
Is there a way to loop through the possible values of Foos?
Basically?
foreach(Foo in Foos)

divinci
- 22,329
- 11
- 45
- 56
510
votes
11 answers
What is the python "with" statement designed for?
I came across the Python with statement for the first time today. I've been using Python lightly for several months and didn't even know of its existence! Given its somewhat obscure status, I thought it would be worth asking:
What is the Python…

fmark
- 57,259
- 27
- 100
- 107
474
votes
28 answers
Why Doesn't C# Allow Static Methods to Implement an Interface?
Why was C# designed this way?
As I understand it, an interface only describes behaviour, and serves the purpose of describing a contractual obligation for classes implementing the interface that certain behaviour is implemented.
If classes wish to…

Kramii
- 8,379
- 4
- 32
- 38
472
votes
21 answers
Expression Versus Statement
I'm asking with regards to c#, but I assume its the same in most other languages.
Does anyone have a good definition of expressions and statements and what the differences are?
user1684
468
votes
22 answers
What does the 'static' keyword do in a class?
To be specific, I was trying this code:
package hello;
public class Hello {
Clock clock = new Clock();
public static void main(String args[]) {
clock.sayTime();
}
}
But it gave the error
Cannot access non-static field in…

Ali
- 261,656
- 265
- 575
- 769
417
votes
6 answers
What's the difference between interface and @interface in java?
I haven't touched Java since using JBuilder in the late 90's while at University, so I'm a little out of touch - at any rate I've been working on a small Java project this week, and using Intellij IDEA as my IDE, for a change of pace from my regular…

Bittercoder
- 11,753
- 10
- 58
- 76
416
votes
17 answers
JavaScript hashmap equivalent
As made clear in update 3 on this answer, this notation:
var hash = {};
hash[X]
does not actually hash the object X; it actually just converts X to a string (via .toString() if it's an object, or some other built-in conversions for various…

Claudiu
- 224,032
- 165
- 485
- 680
388
votes
33 answers
Are there legitimate uses for JavaScript's "with" statement?
Alan Storm's comments in response to my answer regarding the with statement got me thinking. I've seldom found a reason to use this particular language feature, and had never given much thought to how it might cause trouble. Now, I'm curious as to…

Shog9
- 156,901
- 35
- 231
- 235
345
votes
13 answers
How to correctly use lists?
Brief background: Many (most?) contemporary programming languages in widespread use have at least a handful of ADTs [abstract data types] in common, in particular,
string (a sequence comprised of characters)
list (an ordered collection of values),…

doug
- 69,080
- 24
- 165
- 199
308
votes
13 answers
DateTime.Now vs. DateTime.UtcNow
I've been wondering what exactly are the principles of how the two properties work. I know the second one is universal and basically doesn't deal with time zones, but can someone explain in detail how they work and which one should be used in what…

Slavo
- 15,255
- 11
- 47
- 60
255
votes
7 answers
How does "this" keyword work within a function?
I just came across an interesting situation in JavaScript. I have a class with a method that defines several objects using object-literal notation. Inside those objects, the this pointer is being used. From the behavior of the program, I have…

rmeador
- 25,504
- 18
- 62
- 103
216
votes
8 answers
Is SQL or even TSQL Turing Complete?
This came up at the office today. I have no plans of doing such a thing, but theoretically could you write a compiler in SQL? At first glance it appears to me to be turing complete, though extremely cumbersome for many classes of problems.
If it…

Matthew Vines
- 27,253
- 7
- 76
- 97
198
votes
11 answers
Why doesn't a python dict.update() return the object?
I have this code:
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 >…

Paul Tarjan
- 48,968
- 59
- 172
- 213
175
votes
13 answers
What are the differences between "generic" types in C++ and Java?
Java has generics and C++ provides a very strong programming model with templates.
So then, what is the difference between C++ and Java generics?

popopome
- 12,250
- 15
- 44
- 36
159
votes
17 answers
Is there more to an interface than having the correct methods
So lets say I have this interface:
public interface IBox
{
public void setSize(int size);
public int getSize();
public int getArea();
//...and so on
}
And I have a class that implements it:
public class Rectangle implements IBox
{
…

Ali
- 261,656
- 265
- 575
- 769