Please create an account to participate in the Slashdot moderation system

 



Forgot your password?
typodupeerror
×

Comment Re:Easy to read, simple language? (Score 1) 414

But my work has a small number of highly experienced developers. If I was still working at a big soulless corporation with dozens of bottom tier developers mixed in with the seasoned pros, I wonder if this would result in the code being unreadable? I have seen some terrible code in java 4 and 5, I can only imagine the horrors an idiot could wreak with lambdas. Granted, I am sure most of them are still doing java 6 compatible code, since only small companies can afford to change momentum and upgrade.

C# went through this in 2008. It's still around, and practice has shown the fears to be unfounded. Lambdas are heavily used in idiomatic C# today, and many libraries (e.g. ASP.NET MVC) rely heavily on them, and it didn't really have any detrimental effect on code quality.

Comment Re:Java vs. C# amuses me (Score 1) 414

Up until C# 3.5 (when lambdas and LINQ first showed up), C# really wasn't all that different from Java; though it already had non-erased generics, which, I think, are a huge benefit if you use them heavily. It was really 3.5+ that started adding new and very distinct features at a fast pace.

By the way, one thing that GP forgot about (possibly because it's not really used all that much) is "dynamic", which is basically opt-in duck typing.

Comment Re:Yes, and that's why lambdas are a bad idea (Score 1) 414

Lambdas are cryptic in the same way classes are cryptic: it's an unfamiliar concept to many people because they haven't met them yet, but it's also a very powerful concept that makes it possible to write neat, concise and readable code when learned. C# developers were similarly bitching when lambdas were introduced there in 2008, but by now everyone uses them and loves them.

The notion of distinct paradigms is bullshit, anyway. There's no reason why OOP and FP (and other stuff) cannot coexist in the same language.

Comment Re:I think it's really ugly (Score 1) 414

Thing is, there's no reason to have a class for the program (that doesn't actually ever have any instances), and for main to be a static method of the class. That class is completely unnecessary scaffolding, that exists solely because the designers of the language wanted to "simplify" by saying that everything is a method in a class. Every Java application has the same "public static void main" line in it, exactly identical to any other such line. That is a clear indicator that it is superfluous.

In practice, this has an opposite effect for pedagogical purposes, since you have to either explain all those things before getting to something as simple as "Hello, world", or else just handwave them away by saying something along the lines of "you just always type this exact same thing when you want to do this; we'll go over what it actually means later".

In contrast, take something like Python. It does have namespaces, and classes, and objects (and indeed, unlike Java, in Python "everything is an object" is actually true!). But you don't have to know any of that to write or understand "Hello, world", because it also allows for global functions, and for code outside of functions, and it automatically imports the builtins namespace with the most frequently used functions that are useful to get started. So you can explain the basic concepts like variables, conditionals and loops to people first, and then gradually introduce them to procedural programming with functions (and locals and recursion), and then to OOP with classes, and to code structuring with namespaces. And at all levels in this progression, the new skills learned are purely additive - once you learn classes, you can do classes, but things that make more sense as global functions still remain global functions.

It's also nice for app development because you can use the most basic instruments that are necessary for the task at hand. If you're writing a simple console app that reads input, processes it, and spits the result out, you probably don't need any classes, and the language doesn't force you to write any just because.

Comment Re:You must be joking (Score 1) 414

Where the fuck is your pascal snippet reading from?

From the standard input. Which is called "standard" for that exact reason.

How does it abstract bytes to characters?

By using the default conversion that is appropriate for the current locale (note that this is actually implicit in the Java code, as well).

Why is there only an input with no output?

What a stupid question. Because for the purpose of this discussion, we're talking about reading an integer, and nothing more.

Is `read` taking an integer and doing something with it?

Probably the sole valid complaint here. Though the notion of output parameters is not exactly obscure, it's nice when they're spelled out as such at call site, and not just when defined. For example, as in C#: read(out x).

The whole passing in an outvalue thing that C and Pascal do is an AWFUL KLUDGE OF A DESIGN.

Not really, it's just a way to tell the function what type to read. Since you've already explicitly spelled out that type when declaring the variable, there's no reason to repeat it again when reading into that variable. DRY and all that.

Comment Re:Gerrymandering (Score 1) 609

If you're willing to go that far back, I would dispute your assertion that they were always "the party of grownups who have jobs & families, understand cause/effect, understand TAANSTAFL, and participate much more deliberately in the political process". As far as I'm concerned, there's virtually nothing in common between GOP in 1875 and 1975, much less Reagan's times to today.

Comment Re:Not easiest to read, but forgiving... (Score 1) 414

Ironically, you have actually got a few things wrong here.

First of all, delegates are not just function pointers. They're bound method pointers, meaning that they can capture the receiver of the call in addition to the method itself. This makes it possible to create a delegate to an instance method, which is not something you can do with function pointers alone in C++ (there, you need to define a data structure that combines the function pointer with the object pointers; or use something like mem_fn or bind that'll do it for you).

More importantly, when you say that "events are just function pointer lists", this is actually what delegates are, rather than events. Given your definition of Foo, for example, it is possible to say:

Foo f = ...
Foo g = ...
Foo h = f + g; // look, a delegate that references two different methods!

In the most common case, at least when passing them around as arguments, a delegate object will refer to a single method. But it can refer to arbitrarily many methods of different objects, and it's still denoted by the same delegate type. The rules defining what happens when you invoke such a delegate are not obvious (in particular, with respect to return values and out/ref parameters) - order matters, for example, and so do repeated inclusions of the same method (i.e. it's not a set, it's an ordered list).

(In theory, it is possible to have delegate types that are not lists, if you define them as inheriting from Delegate rather than MulticastDelegate on IL level - this is legal per CLI spec. But no .NET language that I know of provides the ability to define such types in practice, so you'd need to use something like ilasm.)

Events, on the other hand, are an entirely different concept altogether. The most crucial difference between an event and a delegate is that event does not define a type, nor is it an object. An event is simply a pattern of two accessor methods - one to add an event handler (represented as a delegate), the other to remove a handler - formalized on language level. When you write something like:

public event EventHandler ShitHappened;

what it does is define two methods named add_ShitHappened and remove_ShitHappened, both taking an argument of type EventHandler. Because you didn't specify the implementation of those methods, it will also automatically generate them as if you wrote it like this:

private EventHandler ShitHappened;
public event EventHandler ShitHappened {
  add { ShitHappened += value; }
  remove { ShitHappened -= value; }
}

(In practice it actually uses atomic operations to ensure that handlers can be registered concurrently from different threads without one overwriting the other, but I've omitted that for the sake of simplicity. For single-threaded case, the above code is equivalent.)

You can't actually write it like that yourself, because it's not legal to have the same name for the field and the event - but for automatically generated accessors it is legal, and distinguishing between them depends on the context where it's done. If you're referencing ShitHappened from the same class, then you're accessing the field. If you're accessing it outside the class, you're accessing the event.

Either way, the important part is that, regardless of whether the event has implicitly defined accessors or not, users of the class only see the add/remove accessors, and do not have access to the backing storage. This means that they cannot, for example, raise the event from the outside, or enumerate the list of subscribers and directly invoke some of them, or remove a delegate from that list that they haven't themselves added (or obtained from elsewhere, which is why it's a good idea to make all event handlers private).

And that is the sole purpose of event: to provide encapsulation for the observer pattern that ensures that code outside of the class can only register and unregister its own handlers, and cannot interfere with handlers from other components, or violate the contract of the class by raising its event at inappropriate times. If you just need a list of function pointers (that anyone can enumerate, mutate and call at will), then that's what delegates are for.

Rough TL;DR version: events are to fields of delegate types what properties are to fields of other types. Both exist for the purpose of encapsulation. An event is not "a list of delegates", though it is a very popular misconception.

Also, while the concepts itself are sound, the actual implementation of all that stuff in CLR and C# could really be better. In particular, the fact that there's Delegate and MulticastDelegate, but then all delegate types actually derive from the latter (and there are no non-multicast delegates in practice). And also the confusion between the event and its backing field for the auto-generated event accessors - it's very common for C# newbies to be confused by the fact that they can do "x.ShitHappened != null" if they're inside the class, but not if they're outside. IMO, they should have completely encapsulated the backing field (like they do for auto-properties), and treat ShitHappened(...) as a special syntax on the event instead of just a direct field access - then they could also add automatic thread-safe null checks that you always have to do anyway. IIRC, that's exactly what VB does.

Comment Re: Yes & the sheer amount of existing code/fr (Score 1) 414

The problem with object.x=4 is that it not overridable, the therefore interferes with both the encapsulation and the specialization concepts within the OO world.

For starters, as noted, it's strictly a language issue - there's no reason why property-style access cannot be made customizable, and it is in C# (just to pick something that's relatively close to Java).

Furthermore, there's no particular reason why you'd really want object.x=4 to be overridable in general. In a language that is designed well, there's simply no observable difference in that operation (and other treatment of 'x') regardless of whether it's a simple field or a code-backed property. Even C# gets it wrong (can't use properties as 'out' or 'ref' arguments of a function, for example), but other languages do it right. In that case, you always start with a field, and you change it to property accessors if and when you actually need it.

Comment Re:More than PR (Score 1) 385

Rand Paul is a grandstander in the Barack Obama mold. He is sound and fury signifies fuck-all but lip-service to a dimwitted ideology that I wonder if he even believes. It's almost as if some consultant told him that the only demographic where he has a chance is bitcoin dudebros and so he has these little events to check off the box.

The only problem with this story is that pandering to "bitcoin dudebros" is widely known to not be a way to electoral success, and if Paul is really just a shrewd grifter that you paint him, he knows that, as well. So what exactly does he stand to gain from participating in the electoral campaign on a platform that practically guarantees a loss?

Slashdot Top Deals

Any circuit design must contain at least one part which is obsolete, two parts which are unobtainable, and three parts which are still under development.

Working...