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 ...
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 ...
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 ...
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 ...
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) ...
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 ...
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 ...
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.
...
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 ...
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 ...
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'...
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, ...
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.
...
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 ...
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 ...
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 ...
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 ...
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'...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
language-features × 151language-design × 58
programming-languages × 53
java × 16
c++ × 16
c# × 13
syntax × 11
object-oriented × 10
language-agnostic × 9
python × 8
c × 7
design × 6
history × 5
javascript × 4
functional-programming × 4
inheritance × 4
compiler × 4
type-systems × 4
comparison × 4
php × 3
coding-style × 3
terminology × 3
exceptions × 3
math × 3
haskell × 3