Questions tagged [magic-string]

A magic string is an input that a programmer believes will never come externally and which activates otherwise hidden functionality. A user of this program would likely provide input that gives an expected response in most situations. However, if the user does in fact innocently provide the pre-defined input, invoking the internal functionality, the program response is often quite unexpected to the user (thus appearing 'magical').

36 questions
2
votes
2 answers

What advantage does using an Enum bring when it's not encoding underlying values?

I understand the sense of using an Enum when it's converting a human-readable string into an underlying (e.g. numeric) value, with the FederalHoliday class in this answer being a good example of that. But the use-case I'm considering is just where…
Tim
  • 1,839
  • 10
  • 18
2
votes
3 answers

Defining your own magic constants in php?

Is there anyway in php, by which we can define our own magic constants, which value could vary throughout the program and how to define variables with the SUPER GLOBAL SCOPE.
mega6382
  • 9,211
  • 17
  • 48
  • 69
2
votes
1 answer

Getting rid of hardcoded strings in JavaScript with ASP.NET MVC

We have a few problems in a project I am working on, where we have a lot of JavaScript files, where we have hardcoded URLs to controller actions. Hardcoded URLs are proned to mistyping Hardcoded URLs in JavaScript scripts will cause a breakage if…
user191152
2
votes
3 answers

How to handle "magic strings" in MVC views, e.g. element id:s?

In my MVC views I frequently need to reference various elements from JavaScript, and for that purpose I define the id attribute for those elements. This is often in conjunction with Ajax calls that update content of various container elements. A…
Kjell Rilbe
  • 1,331
  • 14
  • 39
2
votes
1 answer

bbvEventBroker strongly typed and without magic strings

I would like to use the bbvEventBroker with Ninject, however I am worried about the use of magic strings to connect publisher and subscriber. Is there a strongly typed way to do it without magic strings. Do I need to have a central static magic…
Telavian
  • 3,752
  • 6
  • 36
  • 60
1
vote
0 answers

Add Linter Rule: to localize magic strings - Flutter

I am basically looking for linter rule to recommend the team to localize the magic string in flutter. I am using Visual Code. Do you guys know anything about this? Can I do that? I surfed a-lot but didn't find the rule yet. And, I am new to flutter…
UGandhi
  • 518
  • 1
  • 8
  • 28
1
vote
1 answer

Rollup commonJs and nodeResolve MagicString error

I want to use xml-js library with rollup bundler. After simple import I got an error, that 'json2xml' is not exported by node_modules\xml-js\lib\index.js I tried to fix it with latest version of commonjs rollup plugin. After trying to build, I got…
Zoner
  • 73
  • 8
1
vote
1 answer

shell command # can't be carry out when it not used for comments on colab

I'm confused about this code! Why # cant't play a role that takes the length of a string? string="abcd" !echo ${#string} In fact, the code behind # has become commented and cannot be executed! Any advice?
1
vote
1 answer

Need string manifest to avoid magic strings in webapi c# application

I have a c# webapi application which has magic strings and numbers everywhere. I am asked to change this by having a string manifest or a bundle which holds these strings in one place and refer them. I don’t want to use Enum. I don’t know what is…
Sosa
  • 21
  • 2
1
vote
1 answer

Does logging a string information fall under magic strings?

I would like to know a base thing. _logger.LogInformation("Hi, Am I magic string?"); In the above line, does the string fall under magic string? Any hardcoded validation/action against a response/return is considered a "magic string" to me. (Eg:…
user3814849
1
vote
1 answer

What advantage does using an Enum bring if it's not encoding underlying values?

EDIT: I've heavily edited this question from the original, to focus on the advantages of Enum in this case (the question had been put on hold for being primarily opinion-based) I understand the sense of using an Enum when it's converting a…
Tim
  • 1,839
  • 10
  • 18
1
vote
1 answer

Is there a built in way to avoid magic strings with the Entity Framework's Include()?

Possible Duplicate: Entity Framework Include() strongly typed Ok, I've got an entity framework query where I use Include to tell it I want a related object loaded: var employees = _entities.Employees.Include("Manager").ToList() By using include I…
David
  • 24,700
  • 8
  • 63
  • 83
1
vote
0 answers

Avoiding Magic strings Reflection vs Constant

What would be a better approach to avoid the magic, based on the following 2 examples? Known relationship we know the Class which is meant public string Notes { get { return notes; } set { SetPropertyValue("Notes", ref…
WiiMaxx
  • 5,322
  • 8
  • 51
  • 89
1
vote
1 answer

any solution like T4MVC for external JS files?

I m using T4MVC in MVC project. My question is is there such a solution for external JS files ? Many times there need to use URLs or strings (to compare) in external JS files. A change in sting break application. Or please advice T4MVC can be used…
user576510
  • 5,777
  • 20
  • 81
  • 144
0
votes
2 answers

How to handle "simple" magic values?

I think this is fairly language-independent, but if I'm wrong, then go for C# (or C or C++). With "simple" magic values I mean things like this: if (Value > 0) or while (Value < 0) or while (MyQueue > 0) While writing this (pseudo-code above) it…
Marcus Hansson
  • 816
  • 2
  • 8
  • 17