Tag Info

Hot answers tagged

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.


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?


86

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 ...


82

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 ...


80

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 ...


75

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 ...


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 ...


64

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 ...


62

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: ...


61

Concurrency Java was defined from the start with considerations of concurrency. As often been mentioned shared mutables are problematic. One thing can change another behind the back of another thread without that thread being aware of it. There are a host of multithreaded C++ bugs that have croped up because of a shared string - where one module thought it ...


61

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 ...


60

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.


59

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.


56

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, ...


54

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 ...


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 ...


51

I definitely think that functional programming languages will catch on, so my language will be functional. See Taming Effects with Functional Programming I think the CPUs soon will have hundreads of cores, and threads will he a hell to manage. So the Actor Model is a must instead of threads. See Erlang - software for a concurrent world I also think that OOP ...


50

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 ...


49

Checked exceptions, and exceptions for error handling A pox on an otherwise nice language is its exception handling model. Java badly abuses this. Too many times, there are simple operations (like generating a SHA-1 hash) that cannot possibly fail, and yet throws multiple checked exceptions. In methods that have a very simple failure condition (which is ...


48

Things I would like, as a former long-time PHP apologist: Shorter syntax for arrays. PHP arrays are one of the awesomest features of the language because of their flexibility, but it's a drag to write some_array_method($argity, array('key' => $value));. I believe this proposal was already eviscerated on the PHP mailing list unfortunately. finally ...


48

Make PHP truly object oriented. The slap on another global function evolution of PHP needs to end. array_merge(array_filter(array_intersect_key($arr1, $arr2), "is_int"), $arr3); This is hard for me to read. I have to make my own mental stack and sort of compile it myself. Basically it should read in the reverse. $dog->wakeup()->bark(); is easy to ...


48

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.


48

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 ...


47

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 ...


46

Because functions are mathematical constructs that perform a calculation and return a result. Indeed, much that's "under the hood" of not a few programming languages focuses solely on one input and one output, with multiple inputs being just a thin wrapper around the input - and when a single value output doesn't work, using a single cohesive structure (or ...


45

Unicode Support by default This day and age, programs are being developed to be used internationally, or under the assumption that they might be used internationally. They must provide support for their character sets or render programs written in that language useless.


44

Ditto @paxdiablo. The early programming languages were written by mathematicians--actually all of them were. In mathematics, by her own principle--reading left to right-- it makes sense in the way it works. x = 2y - 4. In mathematics, you would say this: Let x be equal to 2y -4. Also, even in algebra you do this. When you solve an equation for a variable, ...


44

I think the reason is that most popular languages either come from or were influenced by the C family of languages as opposed to functional languages and their root, the lambda calculus. And in these languages, functions are not just another value: In C++, C# and Java, you can overload functions: you can have two functions with the same name, but ...


43

Yes, the designers of C# (and, I'm sure, Java) specifically decided against deterministic finalization. I asked Anders Hejlsberg about this multiple times circa 1999-2002. First, the idea of different semantics for an object based on whether its stack- or heap-based is certainly counter to the unifying design goal of both languages, which was to relieve ...


42

One of my big annoyances is the way switch cases in C-derived languages default to falling through to the next case if you forget to use break. I understand that this is useful in very low level code (eg. Duff's Device), but it is usually inappropriate for application level code, and is a common source of coding errors. I remember in about 1995 when I was ...



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