Jump to content

英文维基 | 中文维基 | 日文维基 | 草榴社区

Talk:Magic string

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

Other Meanings/Examples of the "magic string"

[edit]

ISTM another plausible meaning of "magic string" is just like a magic number but a string instead. This would be a string used to store information that would be better stored using symbolic constants or possibly a boolean variable.

And the string could be purely internal, or it could be in a UI component. The latter is a bit like the kind of magic string that the article talks about, except that rather than being in a text input control, it might be in the text label of a button or the like (this is a form in which I have recently encountered it). That said, maybe this is just one case of a more general kind of anti-pattern for which there ought to be a name: storing state information in GUI controls for later retrieval.

Comments? -- Smjg (talk) 19:38, 16 December 2008 (UTC)[reply]

Mention it in the article. I've actually found another example I hadn't considered previously myself. I'll add when I'm ready to dive back into this thing. --Daydreamer302000 (talk) 07:57, 7 May 2009 (UTC)[reply]

Article needs to be rewritten

[edit]

This article seems to be the result of someone just making up what they believe magic strings to be. Magic strings are analogous to magic numbers and generally refer to the use of strings as a token for some state or entity. I would submit they are referred to as “magic” more as a carry over from its derivation from the concept of magic numbers. The term “magic” here refers to the vagueness in meaning of the token used, or the lack of clarity that exists in how a process enters into the state. —Preceding unsigned comment added by 66.196.25.254 (talk) 15:54, 31 July 2009 (UTC)[reply]

Magic Numbers are numbers seen directly in code with vague or no reference explaining their usage. The reason they are called 'magical' is because programs using such numbers will often function correctly, but no one maintaining the code can readily explain why the program functions correctly since it is not known by anyone currently around just why those particular numbers are there.
This would seem to be a fundamentally different concept from a magic string. Could you expand on how they are analogous, and where the article should be re-written? --Daydreamer302000 (talk) 10:30, 3 August 2009 (UTC)[reply]
Also, there are plenty of valid references regarding both magic numbers and magic strings. If you sincerely think that the parallels between magic numbers and magic strings are so similar as too warrant a merge or re-write of this article, can you provide references, and point out how the references for this article are invalid? --Daydreamer302000 (talk) 10:35, 3 August 2009 (UTC)[reply]

References for Magic String like Magic Number

[edit]

Rswelker: On Daydreamer302000's suggestion, collecting references to one use of the term "magic string", i.e. in reference to a hard-code literal (a token).

  1. "The first 6 bytes are a magic string: exactly “x93NUMPY”." -- SciPy.org: A Simple File Format for NumPy Arrays, Format Specification: Version 1.0
  2. StackOverflow: C# Turning magic string into lambda expression
  3. StackOverflow: Which is the better way to avoid magic string keys? Using string const keys in a class or using enumeration?
  4. StackOverflow: Asp.net MVC UpdateModel() Prefix Without Magic String?

Agree with Preceding Comments

[edit]

As a professional programmer of ~20 years I've always understood it to be like a magic number. Rswelker (talk) 01:09, 23 September 2009 (UTC)[reply]

Daydreamer302000's view may have once been correct and exclusive but it seems common usage is now different - at least in some circles.

Daydreamer302000's Dissent

[edit]
There is obviously some confusion because of the names of these patterns. The word 'Magic' just happens to artificially connect the two terms. They aren't actually related to each other except by that part of their names.
Also the name magic 'string' implies that the secret input might be of a certain computer data type such as a string (or an array of chars). But it in fact could be any kind of input, even a special sequence of actions via an interface by the user, that is the magical input unlocking the otherwise hidden behavior. It need not be any particular data type at all. I think this is confusing to some people.
Likewise, the name magic 'number' implies a numerical data type such as an int, float, double, etc.... However the mystery constant could again be of any type. For example:


   int act(string scene)
   {
     if (scene == "Fireswamp")
       {
         Attack("ROUS'S");
       }
     else if (scene == "Reunion") // In the movie, not the book.
       {
         Cry("As you wiiiiissshhh...");
       }
   }


Here the magic 'number', that is the value used directly in code without any noted reference, explanation, or natural obviousness, is clearly "ROUS'S", even if the data type is clearly a string. (Kudos if you know what that actually stands for.)
Maybe what this article, and perhaps the article on Magic Numbers, needs is a section that clarifies the differences between the two? Would that be acceptable? I'll look at putting something in. Daydreamer302000 (talk) 11:45, 20 October 2009 (UTC)[reply]

Intro makes no sense whatsoever

[edit]

Who wrote this stuff? Does it make any sense? Not from what I can read in the comments. The intro specifically makes no sense whatsoever! Rui ''Gabriel'' Correia (talk) 22:17, 29 January 2014 (UTC)[reply]

If you see an area that needs improvement, please edit the article accordingly. If you don't want to do that, just be a bit more specific here on what you think ought to change, and someone will eventually come along and see to it. Daydreamer302000 (talk) 09:28, 2 February 2015 (UTC)[reply]

Supposed Windows Forms etymology

[edit]

"The term comes from the fact that this type of problem is often seen in Windows Forms with editable text boxes for input."

I'm removing this as it makes no sense. Aside from the claim that this constitutes a "fact", how can one reach the phrase "magic string" from Windows Forms, as opposed to any other GUI API? Indeed, how does one need to go through a GUI (as opposed to a text-based UI or even an input file format) in order to coin this phrase? I've just had a look at the cited reference (in Internet Archive), and it says nothing of the sort.

On browsing the page history, I have found that it previously said "web forms", citing the same reference. But the reference doesn't, as far as I can see, say anything about the etymology of the phrase. Indeed, it seems to me that, literally speaking, it's just a string on which some magical power has been bestowed by the system within which it is used. This is neutral with respect to the mechanism by which it has been input into the system. — Smjg (talk) 13:23, 13 March 2017 (UTC)[reply]