Questions tagged [language-features]

A language feature is a distinct aspect of a programming language, such as binding rules, lexical design, or facets of the type system.

613 questions
1586
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
  • 20,239
  • 11
  • 42
  • 56
458
votes
25 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,098
  • 4
  • 28
  • 36
457
votes
21 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…
Click Upvote
  • 235,452
  • 251
  • 553
  • 736
449
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
448
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
  • 50,804
  • 25
  • 88
  • 106
381
votes
32 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
  • 146,212
  • 34
  • 221
  • 231
372
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
  • 206,738
  • 150
  • 445
  • 651
328
votes
5 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
  • 10,613
  • 9
  • 53
  • 75
326
votes
13 answers

How to Correctly Use Lists in R?

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
  • 65,292
  • 23
  • 156
  • 195
255
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
  • 14,445
  • 10
  • 42
  • 59
251
votes
6 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
  • 24,922
  • 16
  • 59
  • 99
186
votes
6 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
  • 26,003
  • 7
  • 72
  • 94
163
votes
10 answers

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…
Paul Tarjan
  • 44,540
  • 54
  • 163
  • 207
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 { …
Click Upvote
  • 235,452
  • 251
  • 553
  • 736
158
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
  • 11,420
  • 14
  • 40
  • 36
1
2 3
40 41