[fpc-pascal] Food for thought - language string improvement
Michael Van Canneyt
michael at freepascal.org
Mon Jul 10 08:30:37 CEST 2017
On Mon, 10 Jul 2017, Graeme Geldenhuys wrote:
> Hi,
>
>
> Purely on the language side of things.... I love the fact that there is
> no *.h or an "interface section" in my code - why must C/C++ and Object
> Pascal duplicate that information. If I want to see a purely "interface"
> view of my code, the IDE doesn't that as standard in the unit Outline
> window.
If that is all, on the language side, I am a happy man :)
I think Java is a rather primitive language,
so I had hoped for something massively impressive.
Let me give you a counter example why I think Java plainly sucks.
I get very depressed when I see things like this:
dstream.foreachRDD(new VoidFunction<JavaRDD<String>>() {
@Override
public void call(JavaRDD<String> rdd) {
rdd.foreachPartition(new VoidFunction<Iterator<String>>() {
@Override
public void call(Iterator<String> partitionOfRecords) {
Connection connection = ConnectionPool.getConnection();
while (partitionOfRecords.hasNext()) {
connection.send(partitionOfRecords.next());
}
ConnectionPool.returnConnection(connection);
}
});
}
});
Such code is completely unreadable to me.
Compare this to the same code in Python:
def sendPartition(iter):
connection = ConnectionPool.getConnection()
for record in iter:
connection.send(record)
ConnectionPool.returnConnection(connection)
dstream.foreachRDD(lambda rdd: rdd.foreachPartition(sendPartition))
The very paragon of readability.
Or Scala:
dstream.foreachRDD { rdd =>
rdd.foreachPartition { partitionOfRecords =>
val connection = ConnectionPool.getConnection()
partitionOfRecords.foreach(record => connection.send(record))
ConnectionPool.returnConnection(connection)
}
}
Infinitely more readable than Java in my opinion.
And that is what matters to me.
The Java version with all it's templates is just painful.
(And mainly the reason why I think common use of Generics or templates
is just a plain wrong approach, but that is another story)
So in fact your mail is a relief, I thought there would be some killer
arguments why Java is better than Object Pascal...
About the IDE: there I cannot argue, there are probably many more things
that can be done in Lazarus.
Michael.
More information about the fpc-pascal
mailing list