August 09, 2021
On Monday, 9 August 2021 at 18:00:23 UTC, H. S. Teoh wrote:
> I find this to be silly OO-extremism on Java's part.  Static methods of a singleton class are basically free global functions.  Why can't they just *be* global free functions?!  But nooo, that would not jive with the OO agenda, so we have to wrap that in a singleton class just to do lip service to the OO dogma and pacify the OO police.  We're eating the greasy unhealthy food of global free functions, but to pacify our OO conscience we order the diet coke of a singleton class's static methods.

Well, if you're picky, then no, static methods are not free functions in global space, but rather can be considered as methods of object representing the class of objects (x.class). They though are usually used as free functions, and people don't fuss over whether they a free or part of a class.

I think java doesn't have any notion of a global space where you can put your funcs. There is just class and that is it.

To note, I'm not defending the choices made for java by it's dev team, just stated some facts, and personal views.

Best regards,
Alexandru.
August 09, 2021
On Monday, 9 August 2021 at 21:05:05 UTC, H. S. Teoh wrote:
> On Mon, Aug 09, 2021 at 08:18:26PM +0000, Paul Backus via Digitalmars-d wrote:
>> On Monday, 9 August 2021 at 19:23:14 UTC, H. S. Teoh wrote:
>> > As Knuth once said:
>> > 
>> > 	People who are more than casually interested in computers should
>> > 	have at least some idea of what the underlying hardware is like.
>> > 	Otherwise the programs they write will be pretty weird.
>> > 	-- D. Knuth
>> > 
>> > That includes knowing the ugly realities of 2's complement arithmetic.
>> 
>> The way I remember it, 2's complement notation is a method of encoding signed integers as unsigned integers such that a CPU can use the same instructions and circuits for both signed and unsigned arithmetic.
>> 
>> So, from the hardware's point of view, unsigned arithmetic is the pure, simple version, and signed arithmetic is the ugly, complex version. :)
>
> Indeed!  If you look at the assembly level, unsigned arithmetic is the one with straightforward instructions mapping 1-to-1 with arithmetic operations, whereas signed arithmetic is the one that involves carry bits and other such additional complications.

The carry bit is for unsigned arithmetic, it's the overflow flag that is for signed arithmetic. On a 32 bit system carry indicates that bit 31 has overflowed into bit 32, and overflow indicates bit 30 has overflowed into bit 31.

They are mainly for multiword arithmetic.

And whats probably not obvious is that you need unsigned arithmetic to do multiword signed arithmetic, you only use signed arithmetic for the top most word.

August 09, 2021
On Monday, 9 August 2021 at 22:01:33 UTC, Adam D Ruppe wrote:
> On Monday, 9 August 2021 at 21:05:05 UTC, H. S. Teoh wrote:
>> Indeed!  If you look at the assembly level, unsigned arithmetic is the one with straightforward instructions mapping 1-to-1 with arithmetic operations, whereas signed arithmetic is the one that involves carry bits and other such additional complications.
>
> They're literally identical for most operations; you can use the very same instructions and the only difference is how you interpret the data. In x86 they set both carry and overflow flags so you can decide which one you care about.

Since there's only ADD,SUB,MUL(IMUL),DIV(IDIV), it's about 50/50. Half the ops have only unsigned versions, half have signed and unsigned.

IIRC the overflow flag is actually just for catching the error, not for actual arithmetic, since if you're doing signed multiword arithmetic you only use a signed word at the top.

That's why there's ADC, SBB, but no equivalents for the overflow flag.
August 09, 2021
On Monday, 9 August 2021 at 22:57:22 UTC, claptrap wrote:
> Since there's only ADD,SUB,MUL(IMUL),DIV(IDIV), it's about 50/50.

Well, mul is semi-agnostic. It only matters if you look at the high word (which is frequently discarded anyway) and I believe imul works either way. And there's also sar vs shr which are slightly different, while sal and shl are identical.

> IIRC the overflow flag is actually just for catching the error, not for actual arithmetic, since if you're doing signed multiword arithmetic you only use a signed word at the top.

aye.
August 09, 2021
On Mon, Aug 09, 2021 at 10:32:01PM +0000, Alexandru Ermicioi via Digitalmars-d wrote:
> On Monday, 9 August 2021 at 18:00:23 UTC, H. S. Teoh wrote:
> > I find this to be silly OO-extremism on Java's part.  Static methods of a singleton class are basically free global functions.  Why can't they just *be* global free functions?!  But nooo, that would not jive with the OO agenda, so we have to wrap that in a singleton class just to do lip service to the OO dogma and pacify the OO police.  We're eating the greasy unhealthy food of global free functions, but to pacify our OO conscience we order the diet coke of a singleton class's static methods.
> 
> Well, if you're picky, then no, static methods are not free functions in global space, but rather can be considered as methods of object representing the class of objects (x.class). They though are usually used as free functions, and people don't fuss over whether they a free or part of a class.

Frankly, that's just calling a duck an aquatic chicken with webbed feet. The class is a singleton (which kinda defeats the whole point of a *class* -- at that point it might as well be just a namespace, as far as effective semantics are), and the static method does not even take a reference to said singleton class, it's completely standalone and independent (aside from the FQN).  It basically behaves like a global free function -- and is in fact the exact idiom Java uses when interfacing with C functions.  The equivalence is practically 1-to-1.

It quacks like a duck and waddles like a duck -- it's a duck.  Calling it an aquatic class method with webbed feet is really only good for doing lip service to OO dogma. For all practical purposes, it's a free function.


> I think java doesn't have any notion of a global space where you can put your funcs. There is just class and that is it.

Yes, and this is why such a non-OO hack was introduced in the first place.  Since anything existing outside a class is taboo in OO dogma, in order to rationalize away the non-OO-ness of a global free function we wrap it in the robes of a class and crown it as a method of that class. But the class is a singleton (and holds no state) and the method is static (does not depend on the class instance at all), which makes it painfully obvious that the entire intent is to rephrase "global free function" in terms that are less offensive to OO dogma.

But regardless, this shoe-horning doesn't change the fact that it essentially, for all practical purposes, behaves like a global free function.


> To note, I'm not defending the choices made for java by it's dev team, just stated some facts, and personal views.
[...]

No offense taken.  I just find the OO extremism of Java to be laughable, that's all.  Why not just admit that OO isn't the be-all and end-all of programming, and call free global functions what they are.

This is why D's multi-paradigm approach makes so much more sense: sometimes one paradigm doesn't fit the problem, why not acknowledge it and allow a different paradigm to step in.  Not every problem is a nail to which the OO hammer must be brought to bear.


T

-- 
Talk is cheap. Whining is actually free. -- Lars Wirzenius
August 09, 2021
On Mon, Aug 09, 2021 at 10:49:13PM +0000, claptrap via Digitalmars-d wrote: [...]
> And whats probably not obvious is that you need unsigned arithmetic to do multiword signed arithmetic, you only use signed arithmetic for the top most word.

Exactly!! This is why unsigned arithmetic is more basic and fundamental than signed arithmetic.  The latter is built from the former, not the former from the latter.


T

-- 
"You know, maybe we don't *need* enemies." "Yeah, best friends are about all I can take." -- Calvin & Hobbes
August 09, 2021

On 8/9/21 1:14 PM, IGotD- wrote:

>

On Monday, 9 August 2021 at 16:27:28 UTC, Steven Schveighoffer wrote:

>

However, I do know of cases that have gone too far. Like Swift eliminating for loops -- that one stung.

Is this correct?

Yes.

>

for loops with classical C syntax are removed but you can still have for loops over ranges and the x...y syntax just makes an integer range of your liking. This is similar to foreach (i; 0 .. 3) in D.

There are more uses for traditional for loops than just looping over integers or ranges.

>

It's just a syntax change and bugs with ranges is probably just as easy as with the old C syntax.

The use case I had, I needed to rewrite into a sequence. Hm... Let me find the change:

for var i = 0; (gridOrigin.x + CGFloat(i) * subGridSpacing.width) * scale < bounds.width; i += 1 {
...

I wrote a "for generator" sequence type that accepted a lambda for the condition. It now looks like:

for i in forgen(0, condition: { (self.gridOrigin.x + CGFloat($0) * self.subGridSpacing.width) * self.scale < self.bounds.width }){
...

This is just a hack, and not a full replacement. It takes an initial value and an increment (by default 1), and only works with Int.

Honestly, it was a long time ago (heck, they probably removed more features and this won't compile now). There might be better ways. And I probably would have been fine with swift never having for loops. But to start out with them, and then remove them, seemed unnecessary.

-Steve

August 10, 2021
On Monday, 9 August 2021 at 23:09:30 UTC, H. S. Teoh wrote:
> ...
> No offense taken.  I just find the OO extremism of Java to be laughable, that's all.  Why not just admit that OO isn't the be-all and end-all of programming, and call free global functions what they are.
>
> This is why D's multi-paradigm approach makes so much more sense: sometimes one paradigm doesn't fit the problem, why not acknowledge it and allow a different paradigm to step in.  Not every problem is a nail to which the OO hammer must be brought to bear.
>
>
> T

I love how people love to hate Java, yet have no words of hate against OOP in Smalltalk, SELF, Eiffel, Sather, C#, VB, Python (check methods from typeof(func)), Dart.

How has D's multiparadigm helped to have a better marketshare than some of those extremist OOP languages?
August 10, 2021

On Saturday, 7 August 2021 at 12:15:15 UTC, IGotD- wrote:

>

This is a general discussion which applies to all computer languages and also under several decades. What I have observed is that language designers see programmers misuse the language and introduce possible bugs and therefore remove features in languages. An analogy would limit the functionality of cars because people sometimes are involved in accidents, like automatic speed limiter (soon to be law in several countries).

Language designers seem to have a big brother attitude towards programmers and think they will save the world by introducing limitations.

Examples.

Array indexes should be signed instead of unsigned because somehow programmers mess up loops among other things. Bjarne Stroustrup considered his unsigned index to be a historic mistake. While unsigned array indexes make perfectly sense, the bias towards signed seems to be that programmers are stupid. The question is, if can't make a for loop with unsigned math, shouldn't you look for another job?

Somewhat related. when Java was designed, the designer (James Gosling I believe) claimed that programmers were too stupid to understand the difference between signed and unsigned math (despite often several years of university education) and removed signed math entirely from the language. The impact is that when unsigned math is required, you are forced to conversions and library solutions. Not ideal when an HW APIs deals with unsigned numbers for example.

You are welcome to add any other examples that you find significant for the discussion.

This partially applies to D in some extent but can often be found in other languages and mentality of several language designers.

The question is, do you think language designers go to far when trying to "save" programmers from misuse or not?
Do you think there can be approaches that both prevent bugs at the same time do not limit the language?

If there wasn't a need for safe and restrictive languages they probably wouldn't exist. I'd say like most things in this world the drive to make languages safe and easy is money.

https://money.cnn.com/2012/08/09/technology/knight-expensive-computer-bug/index.html

People make mistakes, even the smartest "college/university educated" people. As well, if I want to start a business and I don't need to use a systems language like C that would be nice. I'm sure it's cheaper for a startup to hire python developers to write a backend than it would be to hire C/C++ developers to do the same thing.

Another reason, even more important than the first, would be that bugs can and have killed people.

https://theinsurancenerd.com/therac-25-a-computer-bug-that-killed-many/
https://www.linkedin.com/pulse/real-world-bugs-debugging-embedded-system-stanly-christoper

I'd can probably say with certainty that the people working on these systems were intelligent, had a CS degree and they weren't using D/Go/C#/Java etc... I agree there are some languages that, to me, seem overly restrictive but the fact is I don't have to use or learn them. Imagine how restrictive a language that has mathematical proof that it's type safe, memory safe, runtime exception safe, data-race free and dead-lock free. Take a look at Pony. Too much for me, I'll pass. My point is that it's not that programmers are stupid it's just about safety.

August 10, 2021

On Saturday, 7 August 2021 at 12:15:15 UTC, IGotD- wrote:

>

[...]

Those examples don't feel all that insulting; then again, I am a stupid programmer. However, something that would sting is being deprived of generics because the Elder Gods deemed them too confusing.