Kagamin:
> P.S. you would make a better point if it were a const instance of a class.
You can't even define V as "const struct" and use it like this:
const struct V { double x, y; } // wrong
void main() {
double x = 1, y = 2;
int c = 1;
V v;
switch (c) {
case 1:
On 2011-08-09 07:04, Don wrote:
Jacob Carlborg wrote:
On 2011-08-07 03:19, bearophile wrote:
I have discussed about this topic once in past, but in the meantime I
have seen this is a quite common problem, so I think it doesn't harm
to touch this topic again.
This is a direct D translation of t
Jacob Carlborg wrote:
On 2011-08-07 03:19, bearophile wrote:
I have discussed about this topic once in past, but in the meantime I
have seen this is a quite common problem, so I think it doesn't harm
to touch this topic again.
This is a direct D translation of the original C or C++ code:
//
On 2011-08-07 03:19, bearophile wrote:
I have discussed about this topic once in past, but in the meantime I have seen
this is a quite common problem, so I think it doesn't harm to touch this topic
again.
This is a direct D translation of the original C or C++ code:
// version #1
double foo;
Timon Gehr wrote:
> Lutger Blijdestin wrote:
>> I like the ternary operator the best for this, as it is the simplest. I
>> always write them like this though, liberally include parenthesis and
>> never nest:
>> (condition)
>> ? (truth value)
>> : (false value)
>
> What is the benefit of
Lutger Blijdestin wrote:
> I like the ternary operator the best for this, as it is the simplest. I
> always write them like this though, liberally include parenthesis and never
> nest:
> (condition)
> ? (truth value)
> : (false value)
What is the benefit of this, compared to leaving paren
bearophile wrote:
...
> In my precedent post about this topic I have discussed "nested constness"
> and another partially silly idea. Recently I have seen a language that
> suggests me this:
>
> // version #6
> const foo;
> if (abs(e.x - v.x) > double.min)
> foo = (v.y - e.y) / (v.x - e.x);
>
On Sunday 07 August 2011 06:02:36 Kagamin wrote:
> Jonathan M Davis Wrote:
> > Being able to use const can be very valuable. For instance, what if you
> > were using std.algorithm.copy and got the arguments backwards? If the
> > source is const, then the compiler will complain, and you'll quickly
>
Jonathan M Davis Wrote:
> Being able to use const can be very valuable. For instance, what if you were
> using std.algorithm.copy and got the arguments backwards? If the source is
> const, then the compiler will complain, and you'll quickly find the bug. If
> the
> source isn't const, then you
bearophile Wrote:
> - You can't use "auto" there, so if the type of e.x changes, you have to
> change the foo type manually (double.min is replaceable with typeof(e.x).min).
This is a bad idea too. The code assumes the values are double. If this
assumption is not true, the code is broken.
On Sunday 07 August 2011 04:40:52 Kagamin wrote:
> bearophile Wrote:
> > - And foo can't be const or immutable, I don't like this.
>
> I suppose accidental overwrite bugs are overrated. I have never seen them
> even from evil programmers. If you write random code, overwrite is not your
> only prob
bearophile Wrote:
> - And foo can't be const or immutable, I don't like this.
I suppose accidental overwrite bugs are overrated. I have never seen them even
from evil programmers. If you write random code, overwrite is not your only
problem, you can as well read wrong variable or call wrong fun
P.S. you would make a better point if it were a const instance of a class.
Am 07.08.2011, 06:31 Uhr, schrieb Adam D. Ruppe
:
bearophile:
I agree, that's why I have added two more points
The precedence of the ternary is pretty easy to handle - if there's
more than one thing in there, just use parenthesis. That's the
only thing I can think of that would make it any
bearophile:
> I agree, that's why I have added two more points
The precedence of the ternary is pretty easy to handle - if there's
more than one thing in there, just use parenthesis. That's the
only thing I can think of that would make it any more bug prone
than other branches.
Perhaps it'd be wo
Adam D. Ruppe:
> > I don't like it.
>
> That's not good enough.
I agree, that's why I have added two more points:
- conditional expression is bug-prone and it's a bit tricky (it's a common
source of various bugs), because of it operator precedence too;
- It is less maintainable (if you want to
Reading this post, I kept thinking "why aren't you just using
the ternary operator?"
> I don't like it.
That's not good enough.
I have discussed about this topic once in past, but in the meantime I have seen
this is a quite common problem, so I think it doesn't harm to touch this topic
again.
This is a direct D translation of the original C or C++ code:
// version #1
double foo;
if (abs(e.x - v.x) > double.min)
foo
18 matches
Mail list logo