|
|
Subscribe / Log in / New account

The Grumpy Editor's Python 3 experience

The Grumpy Editor's Python 3 experience

Posted Jul 31, 2018 20:54 UTC (Tue) by lsl (subscriber, #86508)
In reply to: The Grumpy Editor's Python 3 experience by roc
Parent article: The Grumpy Editor's Python 3 experience

Do you actually prefer the symbolic constants for file permissions? Personally, I strongly dislike them and consider the octal numbers to be *much* easier to read. Having to decipher something like "S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH" feels wrong when you can just write 0755.


to post comments

The Grumpy Editor's Python 3 experience

Posted Jul 31, 2018 22:03 UTC (Tue) by k8to (guest, #15413) [Link] (9 responses)

The command line symbols are much clearer. I'm not bothering to decode the C you provided (underlining your point), but this is super clear to me:

chmod u=rwx,go=rx

At least it's super clear compared to the C version.

But I still tend to use the C constants in code as opposed to octal numbers. I think it's a mix of expecting other programmers to come across it who are not UNIX nerds, and the fear of mangling the octal, and a bit of dogmatic fear over magic inline numbers.

The Grumpy Editor's Python 3 experience

Posted Aug 1, 2018 0:19 UTC (Wed) by madscientist (subscriber, #16861) [Link] (4 responses)

It's always really bothered me that the designers of the command line syntax chose "o" and "u". These are terrible, confusing letters. "u" (user) gives no information at all (I'm a user, you're a user, everyone attempting to type this command is a user) and "o" is completely ambiguous because it could stand for "other" but also "owner".

So, it could be "u" means the owner of the file and "o" means other users, or it could be that "o" means the owner of the file and "u" means other users.

Really, it's hard to imagine a worse pair of letters for sowing confusion. In fact the way it makes the most sense to me is exactly the opposite of reality: "o" should be "owner" and "u" should be general users.

That's why I prefer the numerical codes and consider them simpler to get right. Every time I need the text syntax (if I need to do something more sophisticated such as remove the w bit without touching other values) I have to go look up the man page to make sure I have it right. You definitely don't want to mess it up!!

The Grumpy Editor's Python 3 experience

Posted Aug 1, 2018 3:08 UTC (Wed) by k8to (guest, #15413) [Link]

The problem of 'o' and 'u' is not the command line, but really how the flags were named originally. Unless you're objecting to the short form, in which case sure it doesn't help, but command line flags aren't designed for clarity very often.

The Grumpy Editor's Python 3 experience

Posted Aug 1, 2018 11:57 UTC (Wed) by tao (subscriber, #17563) [Link] (2 responses)

I have a hard time seeing how "u=user", "g=group", "o=other", "r=read", "w=write", "x=execute" would be harder to memorise than "second position user", "third position group", "fourth position other", "1=execute", "2=write", "4=read", except if you have a 4th, leading, digit, in which case they are setuid, setgrp, sticky bit...

But I guess we all have different ways of remembering things.

The Grumpy Editor's Python 3 experience

Posted Aug 1, 2018 13:03 UTC (Wed) by madscientist (subscriber, #16861) [Link] (1 responses)

Position is trivial to remember since it's the same way file permissions are shown by ls etc. Most of the detail you suggest isn't used 99% of the time: people really only care about a few possibilities: 4 for read-only and 6 for read-write, then add one if you also want execute.

I already clearly (I think) explained the specific issue I had. I don't object to the text form, and as mentioned I do use it when I need to use the "+" or "-" forms of chmod for example. However I think poor design choices make it harder to use correctly and so I prefer the numeric system on the command line when possible. There's little possibility of mixing up the order of three numbers.

Please note I'm speaking here specifically of the "chmod" command line syntax.

The Grumpy Editor's Python 3 experience

Posted Aug 2, 2018 12:10 UTC (Thu) by tao (subscriber, #17563) [Link]

ls shows rwx though, not the octal equivalent.

The Grumpy Editor's Python 3 experience

Posted Aug 1, 2018 15:50 UTC (Wed) by rweikusat2 (subscriber, #117920) [Link] (3 responses)

That's exactly as 'clear' or 'unclear' as the equivalent

chmod 0755

u=rwx,go=rx has no inherent meaning. It's an arbitrary encoding of an integer using 'letters' and 'funny symbols' instead of numbers.
If you're familiar with the encoding, it's "clear" what it means, if you're not, you won't understand it. One could even call it misleading as go is an English verb which doesn't mean "group and other" (a phrase with doesn't mean anything in itself, either).

I stopped using the 'letters and funny symbols' encoding once I got over my prejudice that 'letters and funny symbols' are somehow 'inherently better' than numbers. For the octal encoding, 1 means execute, 2 means write and 4 means read (also 1 means sticky, 2 setgid and 4 setuid for the fourth set).

The Grumpy Editor's Python 3 experience

Posted Aug 1, 2018 20:47 UTC (Wed) by marcH (subscriber, #57642) [Link] (2 responses)

> It's an arbitrary encoding of an integer using 'letters' and 'funny symbols' instead of numbers.

Those damn, so-called "letters"... I wish email addresses had allowed digits only, they would have been as easy to remember as phone numbers.

The Grumpy Editor's Python 3 experience

Posted Aug 1, 2018 21:42 UTC (Wed) by rweikusat2 (subscriber, #117920) [Link] (1 responses)

UNIX file system permissions aren't phone numbers. This is an integer using 4 adjacent 3-bit groups to encode the corresponding information with 3 of these 4 groups using the same encoding. For 'everyday use' all one needs to remember is that the order is owner - group - world/ other and that 1 means execute, 2 write and 4 read. That's easy enough to remember and it's also not complicated to do additions involving only 1, 2 and 4.

It's certainly not more complicated than remembering PINs or passcodes, something many people apparently do without problems.

It does take a conscious decision to do so, though.

The Grumpy Editor's Python 3 experience

Posted Aug 2, 2018 4:22 UTC (Thu) by marcH (subscriber, #57642) [Link]

> For 'everyday use' all one needs to remember is that the order is User - Group - Other and that 1 means eXecute, 2 Write and 4 Read.

The Grumpy Editor's Python 3 experience

Posted Aug 1, 2018 1:43 UTC (Wed) by Cyberax (✭ supporter ✭, #52523) [Link]

I certainly prefer names. I have never actually used octal in all my life. I know that it exists but meh...

The Grumpy Editor's Python 3 experience

Posted Aug 3, 2018 16:44 UTC (Fri) by mm7323 (subscriber, #87386) [Link]

Most places I've worked at have been against 'magic numbers' in code, both in Coding Standards documents and at review stage.

The reasons are simple and many.

1) giving things a name often help understanding
2) macros or constants provide a convenient place to hang documentation
3) you can easily grep for them to audit use
4) they provide a sort of type hint or type safety depending on language
5) you can Google them much more easily
6) macros can hide expressions or reliance on other macros which helps explain their derivation
7) you can change their definition at a later date without having to search or change lots of code sites


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