Jump to content
Mahdi Safsafi

Typed constants in Delphi.

Recommended Posts

Guest

On side note : i just prepared this and both XE8 and Seattle freeze then crash when building for 64bit, while succeed to 32bit, is this there something i miss here, or just a bug fixed in later versions.

 

WARNING : compiling this might crash your IDE

constsTest.dpr

 

 

Share this post


Link to post

@Lars Fosdal

Quote

And again - I really don't care about the speed penalty.

You shipped a test for comparison !

Quote

I just want constants that are actual constants also when typed and that cannot be changed at runtime.

 

You're asking for immutability ... this is hard to achieve on unmanaged system and specially for Delphi (breaking type-system compatibility). I think placing constants on ROM would be much better as it doesn't require changing the system-type language. What do you think ?

Share this post


Link to post
20 minutes ago, Kas Ob. said:

On side note : i just prepared this and both XE8 and Seattle freeze then crash when building for 64bit, while succeed to 32bit, is this there something i miss here, or just a bug fixed in later versions.

 

WARNING : compiling this might crash your IDE

constsTest.dpr

 

 

Yes that happened to me too !

Splitting constants between two unit, solved the problem.

Share this post


Link to post
22 minutes ago, Mahdi Safsafi said:

You shipped a test for comparison !

He means that the difference in performance is so small as to be unimportant to him

Share this post


Link to post
16 hours ago, Mike Torrettinni said:

Eh, quite disappointing actually. They turned such a good topic into:  https://xkcd.com/386/

I like that. Yes, it was meant as a rather bitter comment. Dear David: Oh, what a noble mind is here o'erthrown!

Share this post


Link to post
1 hour ago, Benmik said:

I like that. Yes, it was meant as a rather bitter comment. Dear David: Oh, what a noble mind is here o'erthrown!

Interesting contribution. Thanks.

Share this post


Link to post
Guest

Here a test for 1 million constant.

 

And this show the inefficiency in 64bit compiler, both project has 1 million constant, the difference between those projects is in using 10k or 20k constant per unit file.

 

The result is

10k project building time with typed defined on 64 is 30s

20k project building time with typed defined on 64 is 56s

 

while on 64bit with untyped constant both are 7.8-8.2s

 

on 32bit the typed constant is slower by something around 1.2s than the untyped which is 5.7-5.9s

 

Can't attach files bigger than 4.8 so here are links to download

ConstTest10k_per_unit.zip https://mega.nz/file/FlsHgJyb#3NXyARerAvxqXAmq0V4pWFgoXZpEycUXD5iHv-Lj6io

ConstTest20k_per_unit.zip https://mega.nz/file/k0lhRboR#olFJQ8fOSkMGL4c2gKygeLPEUAhpGlo4UzYSWlP5OXI

 

Share this post


Link to post
1 hour ago, David Heffernan said:

Interesting contribution. Thanks.

Yes, another one of those sarcastic remarks that are so characteristic for you. But neither great merits as a Delphi programmer nor the sophisticated use of Oxford English entitle you to treat people the way you do, especially on stackoverflow. The slightest slip and you are cracking down on the poor devils, and I might be wrong, but in my opinion it has gotten worse in the recent years. This is still a community of human beings, after all, and they should be treated as such. Friendliness, respect, tactfulness and even a certain warmth are never wrong, even with programmatical sinners and wrongdoers.

Share this post


Link to post
13 minutes ago, Benmik said:

it has gotten worse in the recent years

I have to disagree, it got much better.

Sorry for the interruption, please continue.

Share this post


Link to post
3 hours ago, Benmik said:

Dear David: Oh, what a noble mind is here o'erthrown!

This is what you mean by friendliness, respect, tact is it? Perhaps I'm missing the point.

 

 

Share this post


Link to post
32 minutes ago, Benmik said:

But neither great merits as a Delphi programmer nor the sophisticated use of Oxford English entitle you to treat people the way you do, especially on stackoverflow.

What entitles you to be the judge of that?

 

I don't think I have ever seen David "discipline" anyone (himself included) that didn't deserve it.

Share this post


Link to post
2 hours ago, Kas Ob. said:

Here a test for 1 million constant.

[...]

The result is

10k project building time with typed defined on 64 is 30s

20k project building time with typed defined on 64 is 56s

Well ... so the conclusion is: If you have a project with 1 million (!) typed constants, then the 64bit-compiler is significant slower. Okay. This might be the case. But what now? Feel free to create a bug-report (for me it would be more a feature-request) at Embarcadero.com - I still struggle to find the direction and the goal this discussion still has.

  • Like 1
  • Thanks 1

Share this post


Link to post
1 hour ago, David Heffernan said:

This is what you mean by friendliness, respect, tact is it? Perhaps I'm missing the point.

Yes, I certainly do. To mourn over a "noble mind" that has gone astray is certainly nothing that would make many people feel offended. (In German it's "ein großer Geist" which I like even better). If you feel this is without friendliness, respect or tact then please! go ahead and try using it yourself!

39 minutes ago, Anders Melander said:

What entitles you to be the judge of that? I don't think I have ever seen David "discipline" anyone (himself included) that didn't deserve it.

I'm not a judge, I express a personal opinion. And, with due respect, I intend to continue doing so. In order to prevent me from living in a world with "judges" and "disciplining" people, if they "deserve" it. I cannot believe you actually mean what your second sentence implies.

Edited by Benmik

Share this post


Link to post

@Daniel

Absolutely sure ! No one is insane to use 1 million constants ! A real world example would be using just 32-ordinal-typed-constants (instead of untyped-constants) to implement a binary search tree for a huge number of nodes. This will make a difference at :
- Application size.
- Performance.
- Compilation/Linking time.

Share this post


Link to post
Guest
11 minutes ago, Daniel said:

Well ... so the conclusion is: If you have a project with 1 million (!) typed constants,

No, i didn't say that but my example amplified something slow going on with 64 against 32, it in fact it may has nothing to do with constants at all, because the magnitude of performance degradation

 

with the count of number of constants per unit file, this might help finding and fixing it.

 

15 minutes ago, Daniel said:

I still struggle to find the direction and the goal this discussion still has.

Then delete it.

Share this post


Link to post
5 minutes ago, Kas Ob. said:

Then delete it.

This would be greatly unfair towards Mahdi Safsawi who has put a lot of effort into teaching  us something. I am not the one to judge if he is fully right in everything he says, but I'm grateful for all the people who contribute.

Edited by Benmik

Share this post


Link to post
5 hours ago, Mahdi Safsafi said:
Quote

I just want constants that are actual constants also when typed and that cannot be changed at runtime.

 

You're asking for immutability ... this is hard to achieve on unmanaged system and specially for Delphi (breaking type-system compatibility). I think placing constants on ROM would be much better as it doesn't require changing the system-type language. What do you think ?

 

I think that I really don't care about the underlying implementation detail.

I just want truly constant typed constants.  It would allow me to write consistent, readable, reusable code and allow array parameters and typed constant parameters for attributes.

A minor performance penalty would be acceptable if that goal could be achieved.

  • Like 1

Share this post


Link to post
7 minutes ago, Lars Fosdal said:

I just want truly constant typed constants.  It would allow me to write consistent, readable, reusable code and allow array parameters and typed constant parameters for attributes.

A minor performance penalty would be acceptable if that goal could be achieved.

Surely all full time delphi programmers would be ecstatic with this. 

  • Like 2

Share this post


Link to post
Guest

@Lars Fosdal After you said "be my guest" till this moment my fingers still hurting me, and i am still crying.

 

7 minutes ago, Lars Fosdal said:

I just want truly constant typed constants.  It would allow me to write consistent, readable, reusable code and allow array parameters and type constant parameters for attributes.

A minor performance penalty would be acceptable if that goal could be achieved.

I would love too to see the compiler allowing more low level control over constants, vars, code generation, simply put if the compiler is unable to do better then just let me do it in a Pascal code instead switching to assembly.

Share this post


Link to post
Quote

This would be greatly unfair towards Mahdi Safsafi who has put a lot of effort into teaching  us something.

If this going to make everybody relaxed than I definitely don't mind ! 

I really didn't want things to end like this. I started this topic because I found that Lars question was very interesting and deserves an explanation/discussion. At some point of the discussion, David used a word that made me angry and I just started stopping at the simple slip he makes (I'm not used to do such a thing ... Many of you guys know me from the old G+ community). Eventually, I ended-up showing high qualification than what the topic deserves(Which certainly gives the reader the idea that I'm swaggering). David gave apologies and this proves his high level of education. In my turn, I gave my apologies to @David Heffernan, sorry if I make you uncomfortable(you're a good man and a good developer too), and for everyone who read my topic and followed my discussion.

@Lars Fosdal, @Daniel Feel free to make an action.

Share this post


Link to post

Heated discussions that end well - No problem, IMO.

 

Discussing in writing is always difficult.

Differences such as cultural background and language can make it easy to trip up and come across the wrong way. 

 

As long as we are patient and try to stay positive and on the ball instead of the man - there is hope.

 

 

  • Like 4

Share this post


Link to post
11 hours ago, Benmik said:

To mourn over a "noble mind" that has gone astray is certainly nothing that would make many people feel offended.

It came across as patronising and gleeful. 

 

12 hours ago, Benmik said:

But neither great merits as a Delphi programmer nor the sophisticated use of Oxford English entitle you to treat people the way you do, especially on stackoverflow. The slightest slip and you are cracking down on the poor devils, and I might be wrong, but in my opinion it has gotten worse in the recent years

I don't agree with that. I think anyone who says that doesn't understand Stack Overflow in the round. 

 

There's a huge problem with Stack Overflow, but it's not what you allude to. 

 

In the beginning the site had very little content and there was a void to be filled by asking questions. After some time the majority of questions had been asked and answered. The overwhelming use of the site is a websearch that leads to topic on the site with an existing question that matches the user's needs. Overwhelmingly users get their answers without asking new questions. 

 

Nowadays there are basically two main form for new questions that get asked

 

1. A question is asked that has been asked before. These get closed as duplicates. 

2. A question is asked by a user that has done no debugging. 

 

Closing duplicates is good for everyone.

 

The other form of question has no real value. You can answer the question and the asker learns nothing. Or you can try to help the user learn the value of debugging and so be able to do it for themselves in the future. The site doesn't really make it easy to do this, but i firmly believe it's the right thing to do.

 

As is well known I've spent a lot of time on Stack Overflow over the years. These days I spend very little time there, because interesting questions are so rare. I think perhaps I have a very different perspective of the site than you do given the very different ways that we use them. I think this is an interesting topic, but it's not the topic that this thread is covering. If you want to discuss Stack Overflow, then that would be better in a different thread.

  • Like 1

Share this post


Link to post

David what you said is totally true. But I want to add something : For many times, I saw many people get humiliated for trivial reasons by people that just enjoy doing that and SO is not doing a good job there ! I'm not talking specifically to the Delphi area (I saw that behavior around all SO). Some of my friend refused to use SO just for a moral reason. Moreover, many developers don't agree with their policies.

  • Like 1

Share this post


Link to post
8 minutes ago, Mahdi Safsafi said:

Some of my friend refused to use SO just for a moral reason. Moreover, many developers don't agree with their policies.

That's a valid choice. If you don't agree with the site's policies, then you can choose not to use it. 

 

9 minutes ago, Mahdi Safsafi said:

For many times, I saw many people get humiliated for trivial reasons by people that just enjoy doing that and SO is not doing a good job there !

There is too much of that going on, I agree. 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×