Hot answers tagged

224

The real answer is XML has an L in the name because a guy named Raymond Lorie was among the designers of the first "markup language" at IBM in the 1970'ies. The developers had to find a name for the language so they chose GML because it was the initials of the three developers (Goldfarb, Mosher and Lorie). They then created the backronym Generalized Markup ...


176

Because it is a language. A markup language, not a programming language. Notice that natural human languages like English and Spanish don't "do" anything either. In fact, technically C++ and Java and the like don't "do" anything until they're fed into a compiler and the output gets executed. Doing stuff and being a language are largely orthogonal to each ...


119

I wouldn't mind named parameters. getData(0, 10, filter => NULL, cache => true, removeDups => true); // instead of: getData(0, 10, NULL, true, true); // or how about: img(src => 'blah.jpg', alt => 'an albino platypus', title => 'Yowza!'); Unfortunately the PHP devs shot that idea down already.


111

I'm sure designers of languages like Java or C# knew issues related to existence of null references Of course. Also implementing an option type isn't really much more complex than null references. I beg to differ! The design considerations that went into nullable value types in C# 2 were complex, controversial and difficult. They took the design ...


104

It is very useful in every scenario where one part of class is generated by some custom tool because it allows you to adding custom logic to generated code without inheriting the generated class. Btw. there are also partial methods for the same reason. It is not only about UI but also other technologies like Linq-To-Sql or Entity Framework use this quite ...


103

Let Σ be a non-empty, finite set of symbols, called an alphabet. Then Σ* is the countable infinite set of finite words that can be formed by concatenating zero or more symbols from Σ. Any well-defined subset L ⊆ Σ* is a language. Let's apply this to XML. Its alphabet is the Unicode character set U, which is non-empty and ...


102

The problem is that because in theory any object can be a null and toss an exception when you attempt to use it, your object-oriented code is basically a collection of unexploded bombs. You're right that graceful error handling can be functionally identical to null-checking if statements. But what happens when something you convinced yourself couldn't ...


93

More dereferencing: echo something_that_returns_array()[4]; Others have mentioned named parameters, and shorter array syntax. I wouldn't mind shorter object syntax, as well. $a1 = array(1, 2, 3, 4); $a2 = [1, 2, 3, 4]; $b1 = (object)array('name' => 'foo'); $b2 = {'name' => 'foo'}; // or something?


87

“nth-generation language” is a buzzword. It is a marketing term. There is no universally accepted definition of what exactly defines the “nth generation” for n > 2. Some people categorize “scripting” languages such as Perl or Python as 4GLs because they are much more high-level than C, while others think the defining characteristics of 4GLs is that they're ...


85

It was done because it's the correct thing to do. The fact is that allowing all methods to be overridden is wrong; it leads to the fragile base class problem, where you have no way of telling if a change to the base class will break subclasses. Therefore you must either blacklist the methods that shouldn't be overridden or whitelist the ones that are allowed ...


81

Disclaimer: Since I don't know any language designers personally, any answer I give you will be speculative. From Tony Hoare himself: I call it my billion-dollar mistake. It was the invention of the null reference in 1965. At that time, I was designing the first comprehensive type system for references in an object oriented language (ALGOL W). My goal ...


80

0 is false because they’re both zero elements in common semirings. Even though they are distinct data types, it makes intuitive sense to convert between them because they belong to isomorphic algebraic structures. 0 is the identity for addition and zero for multiplication. This is true for integers and rationals, but not IEEE-754 floating-point numbers: ...


76

Ruby and Python both have benevolent dictators at their helm. They are languages deeply rooted in pragmatic concerns. Those are probably the most significant factors inhibiting fragmentation. Lisp and ML, on the other hand, are more like "design by committee" languages, conceived in academia, for theoretical purposes. Lisp was originally designed by ...


74

null is evil There is a presentation on InfoQ on this topic: Null References: The Billion Dollar Mistake by Tony Hoare Option type The alternative from functional programming is using an Option type, that can contain SOME value or NONE. A good article The “Option” Pattern that discuss the Option type and provide an implementation of it for Java. I have ...


72

After working with PHP for about 13 years, and heavily with JS for about 4, there are a couple things I think PHP would do well to borrow from JS: 1) shorthand notation for Arrays and Objects. I believe this may have been discussed and shot down on Internals (so I hear – I don't like to see how the sausage is made), but I really, really find that the ...


66

Because the math works. FALSE OR TRUE is TRUE, because 0 | 1 is 1. ... insert many other examples here. Traditionally, C programs have conditions like if (someFunctionReturningANumber()) rather than if (someFunctionReturningANumber() != 0) because the concept of zero being equivalent to false is well-understood.


65

Since you asked why C# did it this way, it's best to ask the C# creators. Anders Hejlsberg, the lead architect for C#, answered why they chose not to go with virtual by default (as in Java) in an interview, pertinent snippets are below. Keep in mind that Java has virtual by default with the final keyword to mark a method as non-virtual. Still two concepts ...


64

Suppose we're designing a new language and we want Sqrt to be an instance method. So we look at the double class and begin designing. It obviously has no inputs (other than the instance) and returns a double. We write and test the code. Perfection. But taking the square root of an integer is valid, too, and we don't want to force everyone to convert to ...


63

FORTRAN compilers ignored spaces so: result = value * factor r e s u l t = val ue * fac tor result=value*factor` Were identical as far as the compiler was concerned. Some SQL dialects allow embedded spaces in column names but they need to be surrounded by backquotes or some other delimiter before they can be used.


58

There are three options really, all three of them preferable in different situations. Option 1: parser generators, or 'you need to parse some language and you just want to get it working, dammit' Say, you're asked to build a parser for some ancient data format NOW. Or you need your parser to be fast. Or you need your parser to be easily maintainable. In ...


57

It's because it's important for humans to recognize that functions are not just "another named entity". Sometimes it makes sense to manipulate them as such, but they are still able to be recognized at a glance. It doesn't really matter what the computer thinks about the syntax, as an incomprehensible blob of characters is fine for a machine to interpret, ...


57

Not all objects can be compared, but all objects can be checked for equality. If nothing else, one can see if two objects exist at the same location in memory (reference equality). What does it mean to compareTo() on two Thread objects? How is one thread "greater than" another? How do you compare two ArrayList<T>s? The Object contract applies to all ...


56

Exceptions were invented to help make error handling easier with less code clutter. You should use them in cases when they make error handling easier with less code clutter. This "exceptions only for exceptional circumstances" business stems from a time when exception handling was deemed an unacceptable performance hit. That's no longer the case in the ...


55

I believe the answer lies in the mathematical foundations. Implication is usually considered and defined as a derived, not elementary, operation of boolean algebras. Programming languages follow this convention. This is Proposition I of Chapter II from George Boole's An Investigation of the Laws of Thought (1854): All the operations of Language, as an ...


54

It could be useful to have sometimes, no doubt. Several points argue against such an operator: The characters - and > are valuable, both in isolation and combined. Many languages already use them to mean other things. (And many can't use unicode character sets for their syntax.) Implication is very counter-intuitive, even to logic-minded people such as ...


53

When should an exception be thrown? When it comes to code, I think that following explanation is very helpful: An exception is when a member fails to complete the task it is supposed to perform as indicated by its name. (Jeffry Richter, CLR via C#) Why is it helpful? It suggests that it depends on the context when something should be handled as an ...


53

Finalizers are important for the management of native resources. For example, your object might need to allocate a WidgetHandle from the operating system using a non-Java API. If you don't release that WidgetHandle when your object is GC'd, you're going to be leaking WidgetHandles. What's important is that the "finalizer is never called" cases break down ...


52

Some languages, like Python, support multiple return values natively, while some languages like C# support them via their base libraries. But in general, even in languages that support them, multiple return values are not used often because they're sloppy: Functions that return multiple values are hard to name clearly. It's easy to mistake the order of ...



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