|
|
Subscribe / Log in / New account

Fedora to switch to Python 3 by default

Fedora to switch to Python 3 by default

Posted Oct 25, 2013 22:32 UTC (Fri) by HelloWorld (guest, #56129)
In reply to: Fedora to switch to Python 3 by default by khim
Parent article: Fedora to switch to Python 3 by default

it does not work like that.

Actually most languages got that right by now: Java, C#, Scala, F#, Haskell, Ocaml, SML. Even dynamically-typed ones like Scheme or Ruby. And while not quite strongly-typed, even in C++ the type of 1 == 1 is bool, not int.

Sure. _Bool guarantees that value of the variable is either true or false. Just like in python or other languages.

Python doesn't even have a static type system, how is it supposed to guarantee anything? Hell, Python doesn't even guarantee that True is true, True = False being a valid statement. Oh, and by the way: int guarantees that a variable contains either zero or non-zero, which is entirely isomorphic.

In all other cases C99 bool works at least as well as python's bool.

You mean it's just as useless?

Why would you need to disallow useful and well-defined constructs?

They may be defined, but how are they useful? They're not, they're confusing and nonsensical. Here's what I found when I googled for "C coding guidelines": http://www.jetcafe.org/jim/c-style.html#boolean
http://users.ece.cmu.edu/~eno/coding/CCodingStandard.html#nztest
https://www.kernel.org/doc/Documentation/CodingStyle
Quote from the third:

If the C language included a strong distinction between integers and booleans then the compiler would find these mistakes for us... but it doesn't.

And let's not forget that confusing = and == would never have been an issue if it weren't for C's broken concept of boolean values. Bottom line: everybody agrees that C not having strongly-typed booleans is error-prone and useless.

Well, you've managed to find reason anyway, right: it complicates the language and doesn't provide the benefits.

Having a type-safe boolean is useful, and I'm not the only one to think that, see the above-mentioned languages and coding style documents. It's certainly more useful than _Bool, which doesn't do *anything* an integer couldn't do.

Now you can have perfectly valid code which will suddenly become invalid if you'll include some strange .h file.
Are you serious? Every time you include a header you can break code because somebody #defined an identifier you're using. Every time you use strict; you break legacy code. What you're saying is essentially that Perl should never have bothered with use strict;. Sorry, you're just wrong.


to post comments

Fedora to switch to Python 3 by default

Posted Oct 25, 2013 23:22 UTC (Fri) by khim (subscriber, #9252) [Link] (4 responses)

Actually most languages got that right by now: Java, C#, Scala, F#, Haskell, Ocaml, SML. Even dynamically-typed ones like Scheme or Ruby. And while not quite strongly-typed, even in C++ the type of 1 == 1 is bool, not int.

In C++ type of 1 == 1 may be bool, not int, but this is still perfectly valid C++:

bool foo(bool a, bool b) {
  return a + b;
}

And this is valid, too:

int bar(float x) {
  if (x)
    return 42;
  else
    return 0;
}

Python doesn't even have a static type system, how is it supposed to guarantee anything?

With it's dynamic type system, obviously. If type of object is bool then it's either True or False. And you can even create a nice syntax with decorators!

Hell, Python doesn't even guarantee that True is true, True = False being a valid statement.

That's another side of the python's coin: many constructions which use reserved words in python don't use them and thus can be broken. len = False and range = False are valid, too, but it does not mean they should not use len or range!

Oh, and by the way: int guarantees that a variable contains either zero or non-zero, which is entirely isomorphic.

Sure. And you can even go further and use double instead of int everywhere (as JavaScript does), but it does not mean it's good idea.

They may be defined, but how are they useful?

They are useful when you need to do certain things. Namely: check is some non-boolean variable contains zero or if you want to transform code bool to some flag (in such a case you need to multiply bool by int, of course) or just calculate some kind of weight (where each bool will have one).

One may argue that it's probably not as important and safety will be preferable, but this is separate issue and in a language where you can store float value in an int variable (or the other way around) these look quite natural. Heck, even enum can participate in arithmetic in C! I would be surprised to see bool which can not be used in such a way in C—especially since C++ also allows that.

Bottom line: everybody agrees that C not having strongly-typed booleans is error-prone and useless.

Where everybody is defined as “anyone who's nick is HelloWorld”? It's error-prone, true, but you are the only one who claims that it's useless.

Every time you include a header you can break code because somebody #defined an identifier you're using.

And you can find it and #undef it.

Every time you use strict; you break legacy code.

There are no use strict; in C.

What you're saying is essentially that Perl should never have bothered with use strict;.

No, what I'm saying it that use strict; (and it's GCC's analogue -Werror) must be implemented as capability which is entirely decoupled from all other features. You want to mix it with something else. Sorry, but this is not useful and just plain wrong.

Fedora to switch to Python 3 by default

Posted Oct 26, 2013 0:43 UTC (Sat) by HelloWorld (guest, #56129) [Link]

In C++ type of 1 == 1 may be bool, not int, but this is still perfectly valid C++:
So of all the languages I mentioned you had to pick the one that clearly only allows this kind of nonsense due to having to be compatible with C, despite the fact that I explicitly pointed out that C++'s bool is, in fact, not strongly-typed? Congratulations on that.
With it's dynamic type system, obviously. If type of object is bool then it's either True or False.
So? How does that help in any way, shape or form? It doesn't prevent any errors because obvious nonsense like foo[True] still doesn't blow up.
Sure. And you can even go further and use double instead of int everywhere
Yeah, except that doesn't work because a double is (usually) bigger than an int and can't represent all values of a long long because its mantissa is only 53 bits. Really, try harder.
They are useful when you need to do certain things. Namely: check is some non-boolean variable contains zero or if you want to transform code bool to some flag (in such a case you need to multiply bool by int, of course) or just calculate some kind of weight (where each bool will have one).
All this can be done with trivial helper functions and is certainly not a reason to mess up the type system of the programming language. Sorry, this doesn't match my idea of a useful feature.
And you can find it and #undef it.
Yeah, and if you don't like sane semantics for the bool type, you don't include the header. Duh.
There are no use strict; in C.
So I'm proposing a use strict;-like feature for C and you respond by telling me that... there's no use strict; in C? I mean, honestly?
No, what I'm saying it that use strict; (and it's GCC's analogue -Werror) must be implemented as capability which is entirely decoupled from all other features. You want to mix it with something else. Sorry, but this is not useful and just plain wrong.
So you're saying that the introduction of a new boolean type and the introduction of rules as to what expressions yield values of that type should be separate? I'm sorry, you're insane.

Fedora to switch to Python 3 by default

Posted Oct 26, 2013 1:05 UTC (Sat) by HelloWorld (guest, #56129) [Link] (2 responses)

> One may argue that it's probably not as important and safety will be preferable, but this is separate issue and in a language where you can store float value in an int variable (or the other way around) these look quite natural. Heck, even enum can participate in arithmetic in C! I would be surprised to see bool which can not be used in such a way in C—especially since C++ also allows that.
I actually agree with that, it would be a surprising. And in fact I'm not even saying that things should be done that way. What I'm saying is that they should either a) give the boolean type a sane semantics or b) not add it at all. They instead opted for c) add a boolean type with the same kind of idiocies that affect pretty much everything else in C's type system, thus effectively making it next-to-useless clutter. And sorry, but that's just a clusterfuck.

Fedora to switch to Python 3 by default

Posted Nov 11, 2013 11:48 UTC (Mon) by yeti-dn (guest, #46560) [Link] (1 responses)

You seem to like to word idiotic a lot...

Anyway, the idiotic type system of C is primarily just a representation of the raw machine types. Until processors actually operate with bools (not to be confused with bit flags inside integers), well, bool in C cannot be much more than a fancy name for int. You will not get the distinction you ask for in C. Whether it makes sense to include such thing in C, that is a question, but IMO it carries useful semantics *for the programmer*.

Fedora to switch to Python 3 by default

Posted Nov 12, 2013 8:20 UTC (Tue) by jezuch (subscriber, #52988) [Link]

> Anyway, the idiotic type system of C is primarily just a representation of the raw machine types.

The type system of C is the spirit of the 70's when programs were 1000 times simpler. I read an interview with Thompson recently in which he downplayed the problems with C basically saying "just don't make mistakes". It was kind of disappointing to see him say it, really. But in his times it was 1000 times easier not to make mistakes and he's a smart guy, so I can understand it.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds