Tag Info

New answers tagged

1

Java has this in the form of "final" modifier which can be used also on local variables. It is definitely much less useful than final/readonly class-level fields, but whether it is useful at all is a matter of debate and personal style/preference. On one hand, it can be used to guard against accidental assignments/typos, especially in more complicated ...


4

Since Objective-C inherited its core object-oriented features (minus categories and protocols), including the syntax, from Smalltalk, there's obviously at least Smalltalk that has the same syntax. Plus, all of the Smalltalk descendants such as Self, Newspeak and Fancy.


1

In addition to the other drawbacks that other answers have posited, another is that the Throwable mechanism is designed to be overbearing i.e., it short-circuits normal processing wherever present. Imagine the following public void doSomething(){ Foo it = new Foo(); Bar something = it.doesSomething(); //anything thrown here will cause a hard stop ...


1

Would it be abusive to create an event system that uses try-catch statements and throwables, which are really made for error handling? Abusive is an emotionally loaded term. And it is blatantly subjective ... unless you are measuring a standard that everyone concerned can agree is applicable. What could that standard be? It could be a particular ...


3

I don't understand how would something like that work. After a method throws an exception, it stops executing and permanently gives up control to some exception handler. But after a method raises an event, it gives up control to the event handler only temporarily, and then continues executing. I don't see how could you emulate temporarily giving up control ...


0

By now, http://en.wikipedia.org/wiki/C++11#Range-based_for_loop is a nice alternative to std::for_each. Observe, no explicit iterators: int a[5] = {1, 2, 3, 4, 5}; for (auto &i: a) { i *= 2; } (Inspired by http://stackoverflow.com/a/694534/2097284 .)


2

The only way for a conversion from language X to some intermediate language IL and back to be lossless is for IL to be a superset of X. If you want to have multiple languages as X, then IL has to be a superset of all of them. Therefore, I would suggest that IL has the following structure: delimiter: ---------SOMERANDOMSTRING---------- ...


4

Some intermediate languages have been successfully used as target for a lot of various languages, e.g. LLVM (or Ramsey & Jones' C--, which might be a dead project in 2015) Notice that an intermediate language does not carry all the information provided in the source language (e.g. you are losing information when compiling from C to LLVM). However, I am ...


7

Once a language has been compiled down to assembler or even to say CIL or JVM, concepts such as if statements are lost as they are turned into branches. Not particularly in practice. If you look at a tool like Reflector, it will happily turn CIL back into pretty accurate C# code, ifs and all. So, having said all that, is there a language who's goal ...


9

A similar question has been asked on Stack Overflow. In the accepted answer, Nicol Bolas points out that it isn't in the standard because it has to be proposed and voted on. In the way that C++ works, people write proposals for changes, which are voted on. However, he points out that it's a convenience function and doesn't add that much value over the ...


0

Due to the inexplicable power of rubber duck debugging I have now a solution I find better than all the other approaches I thought of. I will implement a rounding stack. When a subroutine is entered, the last entry will be duplicated and pushed as first element on the stack (It will also be used entry if the stack is completely cleared). The stack is ...


3

I couple of notes: I don't understand your ADD_EXACT problem. If the operation is exact, don't round. Alternatively, if there has to be a rounding step (this includes most FPU operations), it must not introduce error. FMA should probably be a completely separate operation from both addition and multiplication, since its rounding behavior is fundamentally ...


1

The Language Goals for Crystal: Ruby-inspired syntax. Never have to specify the type of a variable or method argument. - Type inference Be able to call C code by writing bindings to it in Crystal. Have compile-time evaluation and generation of code, to avoid boilerplate code. - Templates in C++ Compile to efficient native code. Why is one language ...


0

I was trying to think of why both of these languages went this route instead of inverting it and having == be logical equality and using .ReferenceEquals() for reference equality. Because the latter approach would be confusing. Consider: if (null.ReferenceEquals(null)) System.out.println("ok"); Should this code print "ok", or should it throw a ...


0

Suppose I have two object references: X identifies an instance of String holding the content "George"; Y identifies instance of Point holding the coordinates [12,34]. Consider the following two questions: Do X and Y identify equivalent objects? Should X sort before, after, or equivalent to Y? The fact that X and Y identify instances of unrelated types ...


2

In addition to Snowman's excellent answer, remember that Comparable has been a generic interface for a long time. A type doesn't implement compareTo(object), it implements compareTo(T) where T is its own type. This cannot be implemented on object, since object does not know the class that will be derived from it. object could have defined an ...


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


7

The JLS §4.3.2 defines the class object in the following way: 4.3.2. The Class Object The class Object is a superclass (§8.1.4) of all other classes. All class and array types inherit (§8.4.8) the methods of class Object, which are summarized as follows: The method clone is used to make a duplicate of an object. The method equals ...


1

Another option is to add a rational number type. This is stored as two integers, which usually will need to be multi-precision, and can represent any floating point value including the result of an operation between floating point and a multi-precision integer. This way there is no loss of information. But there is a lot of work involved and should only be ...



Top 50 recent answers are included