IT/Software career thread: Invert binary trees for dollars.

Deathwing

<Bronze Donator>
16,424
7,435
Never heard of this "magic string" concept. I understand it, but I don't understand how 'Keyboard.DOT' protects against it.
 

Tenks

Bronze Knight of the Realm
14,163
606
The only logical thing I can think of is like if they're naming files. So if your format is something like Thing1.Thing2.Thing3

However in the future they may want it to be Thing1#Thing2#Thing3. If you did Keyboard.DOT as the separator you could simply change that constant and not have to touch any of the real code. It is a bad name in this case but that is the only way I could understand it's usage.
 

Lendarios

Trump's Staff
<Gold Donor>
19,360
-17,424
if the context is the actual '.' character, having the constant named Keyboard.DOT is a valid name. You should avoid magic strings, reason been is that is makes things easier to change, and to find where is been referenced. For example, if you want your separator aka dot, to latter be something else, all you have to so is change the value in one place.
Also imagine now that you want to track down where is been used, because somewhere it is been added twice, it is a lot easier to find the usage of the symbol keyboard.Dot( any modern IDE will find symbols and usage with a simple keyboard shortcut) than to do a search string for '.'
 

Deathwing

<Bronze Donator>
16,424
7,435
Sounds like preprocessor macros in C, which are great when used properly.

But, I'm likely still not getting something. How is this a 'magic string' scenario? What's the other way to program this that allows the user to expose hidden functionality?
 

moontayle

Golden Squire
4,302
165
It's specifically used as IP octal separators (firstOctal + keyboard.DOT + secondOctal, etc). Those ain't changing. Didn't know about Magic Strings or Numbers before this but even the best practice research I did on the concept doesn't support something as extreme as this. It's one thing to protect against things changing and needing to avoid the man hours that would go with searching for and changing things contained within thousands of lines of code. This is one step too far. Like Tuco said, might as well just start setting up individual constants for all characters.
 

Lendarios

Trump's Staff
<Gold Donor>
19,360
-17,424
Never heard of this "magic string" concept. I understand it, but I don't understand how 'Keyboard.DOT' protects against it.
Magic strings are when you use string or numbers ( magic numbers) that by themselves have no meaning, and u have to have contextual knowledge to know what it means. For example
Imagine the following code
If any one has to read that the first thing they will ask, is what the F is 1.
Now read this
Everyone can read that the code is executed when the claim type is insurance. It is much more human readable, and you need less contextual knowledge.
Also imagine the following snippet.
All those "1" have different context values, in one is a business logic descriptor, in other is a very dark color, in another is an error code, etc. Now imagine the requirement been changed to, On insurance claims, after applying the premmium, add a fee.

If you do a text search, for "claimType == 1, then is going to miss where is written as "claimType== 1" "or claimType==1", If you do a search for "1" the it will return one million results. Now the best search is Find usage of EnumType.Insurance, that will give you the most refined results posible, and you can see all the places where is been used, and then u make your change there as needed.
 

Deathwing

<Bronze Donator>
16,424
7,435
I agree with those concepts and that's definitely good practice. Wikipedia says magic string is something else entirely:

Magic string - Wikipedia, the free encyclopedia

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").
 

Tenks

Bronze Knight of the Realm
14,163
606
Yeah magic string is more like if you have a REST parameter like &query and generally the user supplies a query and you return with the response. But you have an internal testing thing like DONTQUERYTHROWERROR but for whatever reason an end user does &query=DONTQUERYTHROWERROR and they get a 404 back or something.

As for the actual matter on hand maybe DOT is a bad word possibly it should be like IPSEP or something. But there can be times it is good. Like if you are a bank and in the USA you need to display things as ##,###.## but in the EU you need to display as ##.###,## you can do that fairly easily if you can source in your separators as a property.
 

Tenks

Bronze Knight of the Realm
14,163
606
Yeah his uses an enum but it is pretty similar if you did like private static final INSURANCE = 1 then did if(claimType == INSURANCE)
 

Tuco

I got Tuco'd!
<Gold Donor>
45,447
73,529
Generally magic strings/numbers are bad, but sometimes programmers will learn that generality and contort it into, "Generall strings/numbers are bad" or "don't ever have numbers or strings in your code.". Bad programmers get OCD for stupid shit and then you end up with Keyboard.DOT for an IP address. A bad programmer might say, "Well, what if IPv4 changes standards from 192.168.0.1 to 192:168:0:1? You'll be able to easily handle that!" at which point you just tell him his shit is getting deleted when he gets fired and walk away from the conversation.

xkcd: int(pi)
int_pi.png

Title text: If replacing all the '3's doesn't fix your code, remove the 4s, too, with 'ceiling(pi) / floor(pi) * pi * r^floor(pi)'. Mmm, floor pie.
 

Lendarios

Trump's Staff
<Gold Donor>
19,360
-17,424
I agree with those concepts and that's definitely good practice. Wikipedia says magic string is something else entirely:

Magic string - Wikipedia, the free encyclopedia
Magic number (programming) - Unnamed Contants- Wikipedia, the free encyclopedia


FRom Magic number
Unnamed numerical constants[edit]
The term magic number or magic constant also refers to the programming practice of using numbers directly in source code. This has been referred to as breaking one of the oldest rules of programming, dating back to the COBOL, FORTRAN and PL/1 manuals of the 1960s.[7] The use of unnamed magic numbers in code obscures the developers' intent in choosing that number,[8] increases opportunities for subtle errors (e.g. is every digit correct in 3.14159265358979323846 and is this equal to 3.14159?) and makes it more difficult for the program to be adapted and extended in the future.[9] Replacing all significant magic numbers with named constants makes programs easier to read, understand and maintain.[10]
 

Tuco

I got Tuco'd!
<Gold Donor>
45,447
73,529
A downside to following that practice is often you'll see shit like,

string outOfMemory_errorMessage = "Error: Out of Memory";


And it's used once in the code. In C++ what I find especially annoying is when it's a class member. So you declare the variable outOfMemory_errorMessage in the header, define it in a .cpp file, then use it once in your codebase. Now you've got three lines of code, all of which have their own points of failure, and if a person sees "Error: Out of Memory" in whatever logging system they have they have to go through another layer of obfuscation to find out what is happening.

I generally agree with not having magic numbers/strings, and it just so happens one of my tasks today is to refactor a class and remove some magic numbers, but sometimes people take it too far.
 

Dumar_sl

shitlord
3,712
4
Nope. It's a best practice, but it's a bad one. Give me numbers and above-line comments on them. I don't want a constant that I have to refer back to. I've worked on very, VERY large code bases, and that way is the best way.
 

ShakyJake

<Donor>
7,641
19,281
Nope. It's a best practice, but it's a bad one. Give me numbers and above-line comments on them. I don't want a constant that I have to refer back to. I've worked on very, VERY large code bases, and that way is the best way.
Personally, I hate excessive comments. One of our devs loves to write voluminous comments and it eventually just becomes noise. Your code should be clear as to what it is doing. And, as for magic strings and numbers, that constant should have a descriptive name to make it clear what it represents. You should not have to 'refer back' to a variable in order to understand its meaning.
 

Noodleface

A Mod Real Quick
37,961
14,508
We probably have a couple million lines of code in our BIOS and when people just use numbers it makes no goddamn sense. Sure I can look up a spec to see what's on Bus 0xC6, or you could just define IO_DEVICE_6_BUS as 0xC6.

Also without excessive comments I'd have no clue what a long of pieces of code are doing.

I think it just depends what you're working on, how high/low level it is, and the skill of the developers.
 

ShakyJake

<Donor>
7,641
19,281
On another subject: our team uses the Scrum-Agile process of software development. What is becoming a major issue, in my mind, is how our development is so uncoordinated and unplanned. For example, another dev and I were tasked with adding new reports to a newly created module in our software. Problem is, both him and I basically went off and did our own thing. So now you have these reports in the system, for the same module, that are entirely different from one another. There is no way I could've used his way of doing things as my task was significantly more complex. The problem is, often one doesn't know the complexity of things until you actually get into it. So there was no real way of discovering this stuff completely up-front. It would've been better ifonedev worked on these so at least the code could have been refactored to be consistent across all these new reports. But, of course, this would have slowed down development as all this work would've fallen on one person.

I'm just curious how other teams out there deal with problems like these. And, additionally, I'm not completely sold on the Agile process as it seems to produce very hacky and inconsistent coding practices (OR we're just doing it wrong which is entirely possible).
 

Dumar_sl

shitlord
3,712
4
After you've been in the software engineering world for so long and worked for a few companies, you'll eventually realize all the methodologies, all the ways to organize or coordinate are mostly lines of bullshit. That bullshit isn't intended to actually change the way development is done; it's intended for resume filters and business buzzword usage. It's intended for the salespeople and consultants, not for the actual engineers coding. The actual engineers coding will still in the office at 3am on a Friday night fixing shit during crunch time, regardless of whether his manager is spewing the agile scrum, waterfall, rapid prototyping bs -- whatever he's spewing, the matters of fact of the actual engineer and his development won't change.

Agile scrum environments are the worst of them, from my experience. If you have a manager that actually buys into this line of bullshit, usually they'll arrange the office accordingly: completely open cubes (or tables, which is ridiculous) where there's no privacy and you can hear every conversation, phone call, and passerby.

The first step to becoming a real software engineer is recognizing the circle of bullshit that passes through via the business and managing side. It's usually cyclical and based on the retardedness of the manager.
 

Noodleface

A Mod Real Quick
37,961
14,508
Our group hasn't adapted a SCRUM board yet, but another firmware team has. It basically just looks like what we do, but instead of our boss handing out tasks we'd just pick shit from the backlog.

It's all garbage to me. Useless, waste of time

ShittyCodeReallyUpsetsMe

Granted, I've only been in the game for a few years, maybe my ideas will change. The guys on that team drink the koolaid hardcore.

Speaking of being here until 3AM. Was here until 9PM last night and came in this morning, probably tomorrow too. FUCK MY LIFE