"Niklas Holsti" <niklas.holsti@tidorum.invalid> wrote in message news:lkg1vvF1tp6U1@mid.individual.net...
...
Priorities are just optimization on how to manage cores when there are
not enough of them.
In some contexts it could be optimization -- for example, to increase
throughput in a soft real-time system -- but in hard real-time systems
priorities (or deadlines) are needed for correctness, not just for
optimizatiion.
This I don't buy: priorities never help for correctness. At least not
without extensive static analysis, but if you can do that, you almost certainly can do the correctness without depending upon priorities.
(3) A number of syntax options are eliminated. Matching identifiers are required at the end of subprograms and packages. Initializers are always required (<> can be used if default initialization is needed). Keyword "variable" is needed to declare variables (we do not want the worst option
to be the easiest to write, as it is in Ada).
(10) Variable-returning functions are introduced. They're pretty similar the semantics of anonymous access returns (or the aliased function returns suggested by Tucker). This means that a variable can easily be treated as a function (and indeed, a variable declaration is just syntactic sugar for
such a function).
Square (2) := 3;
List.Index (3) := Item;
Le 06/09/2024 02:03, Randy Brukardt a crit :
(3) A number of syntax options are eliminated. Matching identifiers are
required at the end of subprograms and packages. Initializers are always
required (<> can be used if default initialization is needed). Keyword
"variable" is needed to declare variables (we do not want the worst
option
to be the easiest to write, as it is in Ada).
Why are you considering variables worst than constants?
I don't want the the "worst" option to be the easiest to write, but
neither do I want to put one more keyword in the most common case.
Note that :
1. I have no statistics, but it seems to me that there is more variables than constants in my code.
2. I say "Useless" from my coder point of view, I dont know if it simplify the work for compiler or tools implementers.
Le 06/09/2024 02:03, Randy Brukardt a crit :
(10) Variable-returning functions are introduced. They're pretty similar
the
semantics of anonymous access returns (or the aliased function returns
suggested by Tucker). This means that a variable can easily be treated as >> a
function (and indeed, a variable declaration is just syntactic sugar for
such a function).
I suppose that to allows the compiler to discriminate this non sense code
Square (2) := 3;
from the legitimate
List.Index (3) := Item;
you will have to introduce some specific syntax, like Tucker's "aliased function".
I see the huge benefit from a user point of view, but I'm not aware of compiler internals : doesn't the introduction of a second function type increase complexity?
"One more keyword" is irrelevant in terms of creating code, the only
question is whether it hurts readability.
But how many of them *have* to be variables vs. the number that just are because it is easier? I know I have a number of the latter.
Note that :
1. I have no statistics, but it seems to me that there is more variables
than constants in my code.
But how many of them *have* to be variables vs. the number that just are because it is easier? I know I have a number of the latter.
2. I say "Useless" from my coder point of view, I dont know if it simplify >> the work for compiler or tools implementers.
Constants do help the compiler generate better code, although a lot of the benefits can be gained also by working harder. (That's what C compilers do, after all.)
On 21.12.24 09:14, Randy Brukardt wrote:
Note that :
1. I have no statistics, but it seems to me that there is more variables >>> than constants in my code.
But how many of them *have* to be variables vs. the number that just are
because it is easier? I know I have a number of the latter.
2. I say "Useless" from my coder point of view, I dont know if it
simplify
the work for compiler or tools implementers.
Constants do help the compiler generate better code, although a lot of
the
benefits can be gained also by working harder. (That's what C
compilers do,
after all.)
What are some compilers offering today? That is, can they find declarations of variables that could be constants, if so instructed?
I am seeing some warnings about non-initialized variables for a meaningless mock-up, but not much else. Ada, C++, Java.
(Maybe there are options that I have missed. Or an analysis of a whole program yields more.)
function testc (b : Boolean) return Integer is
package P is
x : Integer;
end;
begin
if b then
P.x := 42;
end if;
return P.x;
end testc;
int testc(bool b) {
struct {
int x;
} P;
if (b) {
P.x = 42;
}
return P.x;
}
class testc {
class P {
int x;
}
P P;
int $(boolean b) {
if (b) {
P.x = 42;
}
return P.x;
}
}
A lot of "variables" in code actually are only written once. In Ada, those are better modeled as constants. A constant tells the reader that the value doesn't change during the life of the object, which is easier for analysis (both human and machine).[...]
Using "constant" for something that isn't going to be modified isExactly the point of Randy. And as Jean-Pierre would say "a program is
good
practice, but I'd say it's for the benefit of the human reader.
I am seeing some warnings about non-initialized variables for a meaningless mock-up, but not much else.
"G.B." <bauhaus@notmyhomepage.invalid> writes:
I am seeing some warnings about non-initialized variables for a meaningless >> mock-up, but not much else.
See -gnatwk, which is included in -gnatwa. Been around for a long time now.
On 22.12.24 13:15, Simon Wright wrote:
"G.B." <bauhaus@notmyhomepage.invalid> writes:
I am seeing some warnings about non-initialized variables for a meaningless >>> mock-up, but not much else.See -gnatwk, which is included in -gnatwa. Been around for a long
time now.
No effect of either here (gcc-14.1.0). I see a CONSTRAINT_ERROR at run time when using the uninitialized return value, for indexing an array.
What are some compilers offering today? That is, can they find
declarations of variables that could be constants, if so instructed?
I put a lot of effort into making sure that all constants are so declared, because I have the rule that (with certain exceptions) no non-local variables may be referenced from subprograms, but constants may be referenced from anywhere.
However, I sometimes have constants that cannot be initialized with a
single expression, resulting in
C : T; -- Constant after initialization
Once C has been initialized, I treat it as a constant. Would your approach allow the compiler to know that C is really a constant?
--
Jeff Carter
"Anyone who cannot cope with mathematics
is not fully human."
The Notebooks of Lazarus Long
214
On 21.12.24 09:14, Randy Brukardt wrote:...
Constants do help the compiler generate better code, although a lot of
the
benefits can be gained also by working harder. (That's what C compilers
do,
after all.)
What are some compilers offering today? That is, can they find
declarations
of variables that could be constants, if so instructed?
| Sysop: | DaiTengu |
|---|---|
| Location: | Appleton, WI |
| Users: | 1,116 |
| Nodes: | 10 (0 / 10) |
| Uptime: | 86:08:53 |
| Calls: | 14,305 |
| Files: | 186,338 |
| D/L today: |
833 files (258M bytes) |
| Messages: | 2,525,504 |