Jump to content

Talk:Magic number (programming)

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Skarz (talk | contribs) at 22:19, 10 March 2024 (OneClickArchived "IDEs and named constants" to Talk:Magic number (programming)/Archive 1). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

"Bjarne Stroustrup on Educating Software Developers" reference in Unnamed numerical constants section

65.78.114.251 has removed a reference to http://www.datamation.com/columns/article.php/3789981/Bjarne-Stroustrup-on-Educating-Software-Developers.htm on the basis that it does not support the point in the text, namely that use of magic numbers "makes it more difficult for the program to be adapted and extended in the future". From the second page of the link:

Take a simple example: A friend of mine looked at the final projects of a class of third-year CS students from a famous university. Essentially all had their code littered with “magic constants.” They had never been taught that was bad style – in fact they had never been taught about programming style because the department “taught computer science; not programming.” That is, programming was seen as a lowly skill that students either did not need or could easily pick up on their own.
I have seen the result of that attitude in new graduate students: It is rare that anyone thinks about the structure of their code or the implications for scaling and maintenance – those are not academic subjects. Students are taught good practical and essential topics, such as algorithms, data structures, machine architecture, programming languages, and “systems,” but only rarely do they “connect the dots” to see how it all fits together in a maintainable program.

and:

The “magic constant” example is indicative. Few students see code as anything but a disposable entity needed to complete the next project and get good grades. Much of the emphasis in teaching encourages that view.

both address the impact of poor practices, specifically citing the use of "magic constants" as an example poor practice, on code maintenance and longevity, which is just another way of saying "adapted and extended in the future". Rwessel (talk) 05:54, 8 February 2014 (UTC)[reply]

Unnamed numerical constants

'It helps detect typos' is disingenuous. Obviously in the example cited the names variable will need to be initialized, and that initial value may just as easily be mistyped. It could be argued that you now have the opportunity to mistype the initial value of the named variable and the variable name itself when referenced. 81.108.216.18 (talk) 15:53, 30 June 2014 (UTC)Phil Short[reply]

Not really. It's reasonably likely that mistyping the variable name will lead to a compilation error. And while the actual definition can certainly be pooched, writing the definition, where only the definition is in play, likely concentrates the mind on that task, leading to a higher chances of being correct (IOW, when you're defining the constant pi, you're just doing that, not also trying to work the formula for the volume of a sphere into your application at the same time). Ad if you do manage to use the constant more than once, you've only got once chance to mess it up rather than several. Finally, having the constant clearly separated makes it easier to verify later. Rwessel (talk) 16:18, 30 June 2014 (UTC)[reply]

Bad coding practices 101

This article needs a link to another article listing bad coding practices. — Preceding unsigned comment added by 206.132.109.103 (talk) 16:13, 8 June 2017 (UTC)[reply]

Hello fellow Wikipedians,

I have just modified 2 external links on Magic number (programming). Please take a moment to review my edit. If you have any questions, or need the bot to ignore the links, or the page altogether, please visit this simple FaQ for additional information. I made the following changes:

When you have finished reviewing my changes, you may follow the instructions on the template below to fix any issues with the URLs.

This message was posted before February 2018. After February 2018, "External links modified" talk page sections are no longer generated or monitored by InternetArchiveBot. No special action is required regarding these talk page notices, other than regular verification using the archive tool instructions below. Editors have permission to delete these "External links modified" talk page sections if they want to de-clutter talk pages, but see the RfC before doing mass systematic removals. This message is updated dynamically through the template {{source check}} (last update: 5 June 2024).

  • If you have discovered URLs which were erroneously considered dead by the bot, you can report them with this tool.
  • If you found an error with any archives or the URLs themselves, you can fix them with this tool.

Cheers.—InternetArchiveBot (Report bug) 14:46, 10 December 2017 (UTC)[reply]

Extended Justification for Most Recent Edit

Some four years ago I added a note to 0xFDFDFDFD that certain debug versions of Win32 functions will flood fill 0xFD during their operation. I chose to add this note to Wikipedia because I had spent significant time looking for what function was responsible for flood filling this magic number in an application I was working on; it is not particularly easy to discover this fact as it is buried halfway through a very large article on this function and does not get mentioned in most places that discuss magic numbers, and I wanted to spare the next poor individual the same agony.

Today I was trying to remember what functions those were, and when I went to the article expecting to see my edit, I found out that it had been removed within about 10 minutes after having been made. I will assume on good faith that the person who removed my edit thought I was being unconstructive. The person in question does not appear to have programming experience (based on reviewing their contributions), so I do not know what criteria that user judged my edit by. The function I listed does not allocate or deallocate memory, so it is entirely separate from the malloc() comment for the same entry. My static IP has made other edits that were fixing typos and had no prior evidence of vandalism. I added a specific citation to MSDN regarding the function in question in the hopes that it isn't reverted again, but I note that most entries do not have any citations and do not end up reverted.

Furthermore, I noticed the entry for D15EA5E had a comment to the effect "Should this be D15EA5ED "Diseased"" It just so happens that I have extensive experience with the Nintendo Wii hardware platform. I know for a fact that the entry is 0D15EA5E; there is no D at the end, and it begins with 0. Look at address 32 (hex 0x20) of any Wii or GameCube ROM with a hex editor.

Finally, I noticed that one entry referred to "uninitialised". While this is British spelling, Wikipedia itself has an article Uninitialized variable but lacks Uninitialised variable. Therefore, I felt justified changing the word. Cheers 98.111.204.114 (talk) 22:11, 16 January 2019 (UTC)[reply]

Magic Number for PDF

Not sure how to change this because so many sources on this conflict each other. However, in the PDF Reference edition 2, it mentions that for many viewers, the magic number only has to appear somewhere in the first 1024 bytes, and not necessarily the first 4 bytes. Skyturnrouge (talk) 22:36, 14 November 2019 (UTC)[reply]

Data type limits

Does § Data type limits really belong in this article? I'm not saying it doesn't belong somewhere, but I am not sure that it belongs here. These limits are not really magic numbers, they are fundamental. The article Integer (computer science), to which Integer type redirects, has them, but only in decimal (and in a sense they are "magic" in decimal as seemingly arbitrary, whereas in hex they are plainly not). I am tempted to add the hex into the Integer article and delete this section: there are no redirects to it, but of course other articles might link to it, and I would check thoroughly they are retargeted if consensus were to make that move.

For that matter, the section should probably be renamed "Integer type limits". 94.21.38.126 (talk) 10:17, 29 November 2019 (UTC)[reply]

I had the same remark. The only justification to keep these limits here would be to provide the name to use instead of writing these magic numbers in code, example INT_MAX in C/C++, however that would become a list of names specific to each language. A reference to headers like <limits.h> in the section "Unnamed numerical constants" should be enough for that article. Teuxe (talk) 13:19, 3 August 2023 (UTC)[reply]

PowerPC Mach-O binaries on Apple Inc.'s macOS platform?!?!?

Fromerly the FEEDFACE Entry read: | FEEDFACE || "Feed face", Seen in PowerPC Mach-O binaries on Apple Inc.'s macOS platform. On Sun Microsystems' Solaris, marks the red zone

Now, I'm very puzzled by this because "MacOS" has never run on PowerPC. OS X 10.5, Leopard (2007) was the last OS to support PowerPC architecture. Perhaps they didn't purge all the PowerPC code, although much of this would also be 32-bit rather than the 64-bit... It just doesn't make much sense that the code would remained buried in there. I replaced it with "Mac OS X" unlinked, as I'm not entirely certain that this doesn't extend past OS X Leopard 10.5 and into Snow Leopard 10.6, for example. Also, linking "Mac OS X" and "OS X" and "OSX" just redirects to "MacOS", so that wouldn't clarify the issue, and just lead to the same confusion. 75.71.166.197 (talk) 01:57, 16 February 2022 (UTC)[reply]

DEC PDP 11/x

DEC PDPs have some affinity to 8x1777777 ( its an octal number ). I will find out, and document it here. — Preceding unsigned comment added by 2600:1700:87D3:22E0:1008:10E6:55:AF7B (talk) 03:36, 3 September 2022 (UTC)[reply]

Advantages of naming magic constants

The second and last item in the list of advantages,

  • It is easier to alter the value of the number, as it is not duplicated. [...]
  • It facilitates parameterization. [...]

strike me as saying essentially the same thing. I would suggest merging the former into the latter. Mjaðveig (talk) 09:30, 25 September 2023 (UTC)[reply]