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?


93

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


89

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


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


86

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


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


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


67

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


67

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


66

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

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


61

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.


61

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.


60

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


57

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


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


55

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


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


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

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


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


47

Languages have copied that from C, and for C, Dennis Ritchie explains that initially, in B (and perhaps early C), there was only one form "&" which depending on the context did a bitwise and or a logical one. Later, each function got its operator, & for the bitwise one and && for for logical one. Then he continues Their tardy ...


47

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


47

The reason C# (and Java and essentially every other OO language developed after C++) did not copy C++'s model in this aspect is because the way C++ does it is a horrendous mess. You correctly identified the relevant points above: struct: value type, no inheritance. class: reference type, has inheritance. Inheritance and value types (or more specifically, ...


45

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



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