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.

language-features
Filter by
Sorted by
Tagged with
1747 votes
8 answers
976k views

How to loop through all enum values in C#? [duplicate]

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? ...
divinci's user avatar
  • 22.7k
514 votes
11 answers
127k views

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 ...
fmark's user avatar
  • 57.9k
480 votes
21 answers
83k views

Expression versus Statement

I'm asking with regards to C#, but I assume it's the same in most other languages. Does anyone have a good definition of expressions and statements and what the differences are?
user avatar
477 votes
28 answers
201k views

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 ...
Kramii's user avatar
  • 8,409
473 votes
22 answers
846k views

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 ...
Ali's user avatar
  • 265k
427 votes
6 answers
156k views

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 ...
Bittercoder's user avatar
  • 11.9k
417 votes
17 answers
812k views

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 ...
Claudiu's user avatar
  • 227k
388 votes
33 answers
71k views

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 ...
346 votes
13 answers
219k views

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 ...
doug's user avatar
  • 69.6k
314 votes
13 answers
302k views

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 ...
Slavo's user avatar
  • 15.3k
255 votes
7 answers
102k views

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 ...
rmeador's user avatar
  • 25.6k
225 votes
8 answers
103k views

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 ...
Matthew Vines's user avatar
201 votes
12 answers
99k views

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", "...
Paul Tarjan's user avatar
  • 49.7k
175 votes
13 answers
116k views

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's user avatar
  • 12.3k
159 votes
17 answers
169k views

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 ...
Ali's user avatar
  • 265k
158 votes
10 answers
9k views

Why are private fields private to the type, not the instance?

In C# (and many other languages) it's perfectly legitimate to access private fields of other instances of the same type. For example: public class Foo { private bool aBool; public void DoBar(...
RichK's user avatar
  • 11.6k
153 votes
10 answers
30k views

What is the tilde (~) in the enum definition?

I'm always surprised that even after using C# for all this time now, I still manage to find things I didn't know about... I've tried searching the internet for this, but using the "~" in a search isn'...
hugoware's user avatar
  • 36.1k
152 votes
2 answers
114k views

Conditional/ternary operator for assignments in Python? [duplicate]

C and many other languages have a conditional (AKA ternary) operator. This allows you to make very terse choices between two values based on the truth of a condition, which makes expressions, ...
Will's user avatar
  • 74.8k
141 votes
3 answers
66k views

VB.NET equivalent of C# property shorthand?

Is there a VB.NET equivalent to the C#: public string FirstName { get; set; } I know you can do Public Property name() As String Get Return _name.ToString End Get Set(ByVal value As ...
Birk's user avatar
  • 2,173
129 votes
12 answers
32k views

Why is there a `null` value in JavaScript?

In JavaScript, there are two values which basically say 'I don't exist' - undefined and null. A property to which a programmer has not assigned anything will be undefined, but in order for a property ...
Christoph's user avatar
  • 167k
128 votes
6 answers
175k views

Use of Begin / End Blocks and the Go keyword in SQL Server?

What are the guidelines as to when to use the BEGIN and END keywords in SQL Server? Also, what exactly does the GO keyword do?
Tarik's user avatar
  • 80.7k
123 votes
9 answers
75k views

What is the purpose of python's inner classes?

Python's inner/nested classes confuse me. Is there something that can't be accomplished without them? If so, what is that thing?
114 votes
5 answers
17k views

The written versions of the logical operators

This is the only place I've ever seen and, or and not listed as actual operators in C++. When I wrote up a test program in NetBeans, I got the red underlining as if there was a syntax error and ...
defectivehalt's user avatar
110 votes
36 answers
42k views

Hidden features of HTML

HTML being the most widely used language (at least as a markup language) has not gotten its due credit. Considering that it has been around for so many years, things like the FORM / INPUT controls ...
100 votes
8 answers
22k views

What unique features does Firebug have that are not built-in to Firefox?

I just cleaned my Firefox addons and wondered: Which features does Firebug have that make it unique? Which features are available in both Firebug and the Firefox Developer Tools?
janpio's user avatar
  • 10.8k
95 votes
18 answers
38k views

Samples of Scala and Java code where Scala code looks simpler/has fewer lines?

I need some code samples (and I also really curious about them) of Scala and Java code which show that Scala code is more simple and concise then code written in Java (of course both samples should ...
Roman's user avatar
  • 65.2k
95 votes
8 answers
77k views

Python: How to pass more than one argument to the property getter?

Consider the following example: class A: @property def x(self): return 5 So, of course calling the a = A(); a.x will return 5 But imagine that you want to be able to modify the property x. ...
Rizo's user avatar
  • 3,083
86 votes
3 answers
17k views

Why isn't the eigenclass equivalent to self.class, when it looks so similar?

I've missed the memo somewhere, and I hope you'll explain this to me. Why is the eigenclass of an object different from self.class? class Foo def initialize(symbol) eigenclass = class << ...
Robert K's user avatar
  • 30.2k
85 votes
9 answers
31k views

Why C# doesn't implement indexed properties?

I know, I know... Eric Lippert's answer to this kind of question is usually something like "because it wasn't worth the cost of designing, implementing, testing and documenting it". But still, I'd ...
Thomas Levesque's user avatar
83 votes
18 answers
41k views

What are C macros useful for?

I have written a little bit of C, and I can read it well enough to get a general idea of what it is doing, but every time I have encountered a macro it has thrown me completely. I end up having to ...
Jack Ryan's user avatar
  • 8,436
75 votes
4 answers
27k views

Python type() or __class__, == or is

I want to test whether an object is an instance of a class, and only this class (no subclasses). I could do it either with: obj.__class__ == Foo obj.__class__ is Foo type(obj) == Foo type(obj) is Foo ...
mgibsonbr's user avatar
  • 21.9k
70 votes
4 answers
61k views

What's the difference between a hash and hash reference in Perl?

I would like to properly understand hashes in Perl. I've had to use Perl intermittently for quite some time and mostly whenever I need to do it, it's mostly related to text processing. And everytime, ...
user855's user avatar
  • 19.4k
69 votes
12 answers
34k views

Will a future version of .NET support tuples in C#?

.Net 3.5 doesn't support tuples. Too bad, But not sure whether the future version of .net will support tuples or not?
Graviton's user avatar
  • 82.6k
69 votes
5 answers
26k views

Double dispatch in C#?

I have heard/read the term but don't quite understand what it means. When should I use this technique and how would I use it? Can anyone provide a good code sample?
Oded's user avatar
  • 494k
67 votes
5 answers
12k views

Why does Java permit escaped unicode characters in the source code?

I recently learned that Unicode is permitted within Java source code not only as Unicode characters (eg. double π = Math.PI; ) but also as escaped sequences (eg. double \u03C0 = Math.PI; ). The first ...
Zaven Nahapetyan's user avatar
62 votes
8 answers
18k views

Javascript as a functional language

I am looking get to grips with functional programming concepts. I've used Javascript for many years for client side scripting in web applications and apart from using prototypes it was all simple DOM ...
Ash's user avatar
  • 61.6k
62 votes
1 answer
1k views

Problem understanding C# type inference as described in the language specification

The C# language specification describes type inference in Section §7.5.2. There is a detail in it that I don’t understand. Consider the following case: // declaration void Method<T>(T obj, Func&...
Timwi's user avatar
  • 65.9k
58 votes
9 answers
8k views

Why isn't there an endianness modifier in C++ like there is for signedness?

(I guess this question could apply to many typed languages, but I chose to use C++ as an example.) Why is there no way to just write: struct foo { little int x; // little-endian big long ...
Lena Schimmel's user avatar
54 votes
5 answers
38k views

C# method call with parameter name and colon

I've begun to notice at times when I'm making method calls in C# that the names of the parameters for the method I'm calling will show up in the intellisense list appended with a colon, and that I can ...
Zann Anderson's user avatar
52 votes
6 answers
47k views

What is a maximum number of arguments in a Python function?

It's somewhat common knowledge that Python functions can have a maximum of 256 arguments. What I'm curious to know is if this limit applies to *args and **kwargs when they're unrolled in the ...
Soviut's user avatar
  • 89.9k
49 votes
6 answers
11k views

Methods in Ruby: objects or not?

Inspired by this discussion, after some googling I wasn't able to find an answer to a pretty simple question regarding methods in Ruby: are methods objects or not? There are different opinions here ...
Mladen Jablanović's user avatar
48 votes
4 answers
43k views

Why do enums have computed properties but not stored properties in Swift?

I am new to Swift and just came across this in the documentation: Computed properties are provided by classes, structures, and enumerations. Stored properties are provided only by classes and ...
Adit Gupta's user avatar
  • 1,334
47 votes
7 answers
89k views

What is the purpose of long, double, byte, char in Java?

So I'm learning java, and I have a question. It seems that the types int, boolean and string will be good for just about everything I'll ever need in terms of variables, except perhaps float could be ...
Ali's user avatar
  • 265k
45 votes
5 answers
23k views

Anonymous type and tuple

What is the difference between anonymous type and tuple?
Amutha's user avatar
  • 541
44 votes
2 answers
14k views

Equivalent of Class Loaders in .NET

Does anyone know if it possible to define the equivalent of a "java custom class loader" in .NET? To give a little background: I am in the process of developing a new programming language that ...
Scott Wisniewski's user avatar
43 votes
1 answer
16k views

Why doesn't Java varargs support collections?

In my Java code I often use the very handy method(Class... args) varargs. As far as I know, they allow you to pass any amount of Class objects or an array of Class[]. Since I also often use the Java ...
tb189's user avatar
  • 1,972
41 votes
6 answers
39k views

What is the difference between VB and VBScript

What is the difference between VB and VBScript?
DNR's user avatar
  • 3,706
40 votes
20 answers
3k views

Have you ever restricted yourself to using a subset of language features? [closed]

Have you ever restricted yourself to using a subset of language features, and more importantly, why? I'm curious to find out who choose to use only certain language features and avoid others in order ...
38 votes
3 answers
12k views

Java's switch equivalent in Clojure?

Is there an equivalent for Java's switch construct in Clojure? If yes, what is it? If no, do we have to use if else ladder to achieve it?
vikbehal's user avatar
  • 1,524
36 votes
1 answer
21k views

What's the new way to iterate over a Java Map in Scala 2.8.0?

How does scala.collection.JavaConversions supercede the answers given in Stack Overflow question Iterating over Java collections in Scala (it doesn't work because the "jcl" package is gone) and in ...
Alex R's user avatar
  • 11.6k

1
2 3 4 5
13