Skip to main content
96 votes
Accepted

In C#, why are variables declared inside a try block limited in scope?

What if your code was: try { MethodThatMightThrow(); var firstVariable = 1; } catch {} try { var secondVariable = firstVariable; } catch {} Now you'd be trying to use an undeclared ...
Ben Aaronson's user avatar
  • 6,963
67 votes

In C#, why are variables declared inside a try block limited in scope?

I know that this has been well answered by Ben, but I wanted to address the consistency POV that was conveniently pushed aside. Assuming that try/catch blocks didn't affect scope, then you would end ...
Peter M's user avatar
  • 2,049
47 votes

In OOP, isn't the 'protected' keyword required?

It depends on what you mean by "required". Access modifiers are not a necessity. You could replace every access modifier with public and most applications will work just like they did when you used ...
Flater's user avatar
  • 54.8k
41 votes
Accepted

Why don't programming languages or IDEs support attaching descriptive metadata to variables?

Why doesn't it exist? The direct answer here is that this isn't technically impossible, no one has just been sufficiently bothered enough by it to create a field-spanning standard that everyone can ...
Flater's user avatar
  • 54.8k
39 votes

Programming language where every function call/block is done in a separate thread?

every function call/new block (if clauses, loops etc) will work in a separate thread. Read a lot more about continuations and continuation-passing style (and their relation to threads or coroutines) ...
Basile Starynkevitch's user avatar
39 votes

Why don't programming languages or IDEs support attaching descriptive metadata to variables?

TLDR Decomposition makes names shorter. Do not fight symptoms, solve underlying problem instead. Scope is important Naming is the hardest problem, not because long names are not readable, but because ...
Basilevs's user avatar
  • 2,809
38 votes

In OOP, isn't the 'protected' keyword required?

No, it's not required: Bjarne Stroustrup, explained how he naively added protected to C++ release 1.2, thinking to provide a useful feature to class developers, just to conclude only 5 years later ...
Christophe's user avatar
  • 79.9k
37 votes

Programming language where every function call/block is done in a separate thread?

You may be interested in reading about the research into data parallel Haskell. If you search around on youtube, Simon Peyton Jones has given some interesting talks related to the subject as well. ...
Karl Bielefeldt's user avatar
29 votes
Accepted

Can Just-In-Time compilation be considered a secure feature?

JIT compilation is risky because of the W^X violation: at runtime, it is possible to generate new code, similar to an eval() in dynamic languages. But being able to dynamically generate executable ...
amon's user avatar
  • 135k
28 votes

Why don't programming languages or IDEs support attaching descriptive metadata to variables?

Java and C# at least have this sort of feature. Javadoc is the system for it in the Java context, Documentation comments in C# context. Indeed, that’s how IDEs provide on-hover info at all. Generally ...
Telastyn's user avatar
  • 110k
23 votes

In C#, why are variables declared inside a try block limited in scope?

Consistency-sake aside, wouldn't it make sense for us to be able to wrap our code with error handling without the need to refactor? To answer this, it's necessary to look at more than just a variable'...
Eliah Kagan's user avatar
20 votes
Accepted

Why is having a NotImplementedException a good thing?

It allows the code to compile for your method stub (regardless of the method's return type), while you get around to putting in an implementation. It also reminds you to put in the implementation, ...
Robert Harvey's user avatar
16 votes
Accepted

Logically, is there a reason why ++i++ can not be a valid expression?

You are misinterpreting GCC's error message: <source>:5:8: error: lvalue required as increment operand ++i++; ^ Note where the error message is pointing: the postfix++ part. ...
Nicol Bolas's user avatar
15 votes

Programming language where every function call/block is done in a separate thread?

This is exactly what Erlang does. It handles rejoining the threads mostly by using queues. It`s a brilliant concept but a bit difficult to wrap your head around initially if your background is more ...
GenericJam's user avatar
15 votes
Accepted

Is having a generator language facility such as `yield` a good idea?

Caveats first - C# is the language I know best, and while it has a yield that seems to be very similar to other languages' yield, there may be subtle differences I am unaware of. I am concerned ...
Telastyn's user avatar
  • 110k
14 votes

Why does HTML collapse whitespace?

In HTML, line breaks are inserted at rendering time in order to make the line length fit the width of the screen. This is in contrast to both plain text formats and layout formats like PDF where line ...
JacquesB's user avatar
  • 60k
13 votes

Is having a generator language facility such as `yield` a good idea?

Is having a generator language facility such as yield a good idea? I'd like to answer this from a Python perspective with an emphatic yes, it's a great idea. I'll start by addressing some questions ...
Joel Harmon's user avatar
  • 1,073
12 votes

Do any programming languages use types as values? Would there be any point?

Do any programming languages use types as values? Most languages that even have types (your question doesn't make sense for languages like ECMAScript, Python, Ruby, Smalltalk, Magpie, etc. which don'...
Jörg W Mittag's user avatar
12 votes

Why don't programming languages or IDEs support attaching descriptive metadata to variables?

It's a good question, and some IDEs do have the functionality you suggest, but virtually all programming languages and IDEs have the simple ability to add comments like so: // The lowest integer ...
Steve's user avatar
  • 10.3k
10 votes
Accepted

What do you need Covariant Return Types for?

Firstly, it is worth noting that the article is very likely wrong. There is currently a long list of features officially earmarked for C# 8.0, but covariant return types is not one of them. That ...
David Arno's user avatar
  • 39.4k
10 votes
Accepted

API across multiple languages. Use idiomatic code for each or support the same API structure

Conform to the language and not to the project API. The reason is simple. No matter how important a service is, how much mindshare it occupies in your consciousness or that of its maintainers... it ...
Kilian Foth's user avatar
9 votes

Was Java the first programming language to support inner classes?

The first language with nested classes was Beta, a successor to Simula. They are carried even further in Beta's successor, gBeta. A modern language that carries them quite far is Newspeak. Scala's ...
Jörg W Mittag's user avatar
9 votes

In OOP, isn't the 'protected' keyword required?

Python is also a language that strongly adheres to the object oriented programming approach. It uses the classical approach of classes and objects. The thing to remember however is that any "word" is ...
paul23's user avatar
  • 1,101
8 votes

Was template meta programming really discovered "by accident"?

There is more to invention than giving a simple list of implications and with C++ Stroustrup aimed for generality: I'm not interested in a language that can only do what I can imagine This is from ...
manlio's user avatar
  • 4,236
8 votes
Accepted

Is it important that a language is coherent to itself?

Let's be honest - nobody* is going to use your language. You're not going to get it done, or it's not going to work, or it's going to be too slow, or it's not going to be useful, or you're not going ...
Telastyn's user avatar
  • 110k
8 votes

Why don't OOP languages offer a feature to clone a parent into a child class?

Is it possible to easily clone a parent into a child ? Some languages allow this by specifying the base class constructor. Here in C++: class MyParentClass { public: int MyInt; }; class ...
Christophe's user avatar
  • 79.9k
8 votes

In OOP, isn't the 'protected' keyword required?

Before we decide that the protected access modifier must be removed from all popular OO languages I would like to point out that it would be pretty inconvenient to lose it. In abstract base classes ...
Martin Maat's user avatar
  • 18.5k
8 votes
Accepted

Do any programming languages use types as values? Would there be any point?

Yes, any languages where classes are first class objects would allows classes to be used as value in a variable. I don't know if there's a widely accepted name for this kind of behaviour, but this is ...
Lie Ryan's user avatar
  • 12.4k
8 votes

Can Just-In-Time compilation be considered a secure feature?

For programs written in some high-level language, there is always an execution environment necessary. This can be a Just-in-Time compiler, an Ahead-of-Time compiler, an interpreter, or a combination ...
Doc Brown's user avatar
  • 211k
8 votes
Accepted

Does a programming language with ML-style modules need packages?

Modules and packages solve different problems, though they certainly overlap, and can be made nearly synonymous. Packages provide a critical source of namespacing. Modules aren't guaranteed unique ...
Kenogu Labz's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible