Talk:Extract file extension: Difference between revisions

(added a new talk section.)
 
(13 intermediate revisions by 5 users not shown)
Line 1:
==a new contributor==
 
Hi, I was a quiet reader but decided to contribute now. That is my first every wiki-like article so please excuse my mistakes and kindly tell how to improve. :)
 
Line 8 ⟶ 10:
Yes, you are right. My C# code needs to be updated. I will try to do that, when I find time.
 
===definition of a legal file extension===
 
If the &nbsp; ''file extension'' &nbsp; appears &nbsp; '''after''' &nbsp; the last period (using the first example), then the file extension should be &nbsp; <big>'''jpg'''</big>, &nbsp; and not &nbsp; <big>'''.jpg'''</big> &nbsp; (just a nitpick). &nbsp; Also note that &nbsp; <big>'''.jpg'''</big> &nbsp; contains a non-alphanumeric character, namely the period. &nbsp; In various documents that I read, the file extension is to the &nbsp; ''right'' &nbsp; of the last period (with other caveats, of course), and does not include the period. &nbsp; But other sites do include the period, so ... -- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 23:26, 4 May 2015 (UTC)
Line 16 ⟶ 18:
Also, I would use the word &nbsp; '''digits''' &nbsp; (or better yet, &nbsp; '''decimal digits''') &nbsp; instead of &nbsp; '''numbers''' &nbsp; when defining a legal file extension (for this Rosetta Code task). -- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 23:42, 4 May 2015 (UTC)
 
It wouldn't hurt to define what a &nbsp; '''letter''' &nbsp; is; &nbsp; I assume you meant lower and uppercase versions of the Latin (Roman) alphabet. &nbsp; If so, specifically mention them. &nbsp; I don't likefeel comfortable assuming what youwas meantstated. -- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 23:42, 4 May 2015 (UTC)
 
'''<big><big><math>\pi</math></big></big>Numerals''' &nbsp; is a number,better &nbsp;word soto isuse instead of &nbsp; '''+1.5numbers''' &nbsp; andin &nbsp;this '''-6'''case. &nbsp; -- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 2303:4225, 45 May 2015 (UTC)
 
'''<big><big><math>\pi</math></big></big>''' &nbsp; (pi) &nbsp; is a number, &nbsp; so is &nbsp;'''+1.5''' &nbsp; and &nbsp; '''-6'''. &nbsp; -- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 23:42, 4 May 2015 (UTC)
 
 
Another also:
 
The 2nd part of the definition of a filename extension states that:
* consists of a period, followed by one or more ASCII letters or digits (A-Z, a-z, 0-9)
I would argue that the filename &nbsp;
abc._#5
fits that requirement as the numeral &nbsp; '''5''' &nbsp; follows the period.
 
Therefore, the following would be more apt:
* consists of a period, followed ''solely'' by one or more ASCII letters or digits (A-Z, a-z, 0-9)
which would exclude any extraneous characters.
 
And, yes, I know that one of the test cases (examples) shows this, but examples shouldn't be used as definitions. -- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 17:40, 31 August 2016 (UTC)
 
: Updated. --[[User:Smls|Smls]] ([[User talk:Smls|talk]]) 06:19, 1 September 2016 (UTC)
 
Another case I find useful is "libglfw.so.3.1" => "so", and always returning lowercase results. Just sayin [[User:Petelomax|Pete Lomax]] ([[User talk:Petelomax|talk]]) 12:18, 9 September 2016 (UTC)
 
In Unix and Unix-like environments
.desktop
is a hidden file or directory and not a file extension.
 
: Updated:--[[User:Garak|Garak]] ([[User talk:Garak|talk]]) 12:34, 21 December 2017 (UTC):
 
:: That's why the specification says "For the purposes of this task", and the task allows showing a built-in standard library function that behaves differently. --[[User:Smls|Smls]] ([[User talk:Smls|talk]]) 16:32, 21 December 2017 (UTC)
 
== Use Libraries not Footguns ==
 
Practicing programmers should strongly prefer to use existing filesystem APIs to extract file extensions.
 
Why?
 
1. Doing this correctly depends on the operating system (OS).
 
2. Such OS APIs exist for a reason! Use them!
 
3. Generally speaking, handling strings correctly is harder than many programmers realize. There are many gotchas in doing this correctly.
 
4. You need to be smart about encodings and locales.
 
Therefore, for the sake of being *responsible* about what information Rosetta Code provides, it should do the following:
 
A. Make it abundantly clear that ad-hoc solutions are *not* applicable for real-world usage.
 
B. Point readers to the relevant APIs in their languages, operating systems, and libraries.
 
--[[User:Krebsikl|Krebsikl]] ([[User talk:Krebsikl|talk]]) 15:27, 7 August 2023 (UTC)
'''<big><big><math>\pi</math></big></big>''' &nbsp; is a number, &nbsp; so is &nbsp;'''+1.5''' &nbsp; and &nbsp; '''-6'''. &nbsp; -- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 23:42, 4 May 2015 (UTC)
: It would help if you could name even just one of them, and at least one example that c/would go horribly wrong. I was not aware of any suitable OS APIs for this, perhaps you meant PathCchFindExtension, but that is not capable of solving this task. I would agree that handling strings is much harder than it should be, and quite ridiculously so in most popular (/terrible) programming languages, and via most OS APIs. If some task on rc is not suitable for real-world use, then (like you just have) you need to start a debate on that task's discussion page, and (possibly with a limited few exceptions for complexity or security reasons) try and lick the task into something that '''is''' useful, since comparing programming languages (the whole purpose of this site) for completely unusable tasks is, well, all rather pointless. --[[User:Petelomax|Petelomax]] ([[User talk:Petelomax|talk]]) 15:48, 9 August 2023 (UTC)
7,794

edits