People use code-switching all the time in their lives - you don't use the same words, jargon, slang, etc. when you are talking to your friends, your family, or in a business situation. Sometimes, it's about fitting in with a group. Sometimes, it's a matter of how easy it is to communicate. Sometimes, it's even for emphasis. Capische?
But what does this have to do with writing?
Writers can code-switch, too, not just by using slang or other language words, but also by choosing how formal they are with grammar and colloquial phrasing, or even using a specific vernacular.
It's like, you gotta have a kinda voice when you talkin' to casual peeps or they get all up in your face 'bout how snotty you come across.
Alternatively, certain personages require a level of formality and adherence to formal grammatical practices that are often--but not always--agreed upon. Sadly, the assumption of the universality of these grammatical rules is not quite factual.
Right-o. There's some things that are seen as being more common then they really are. People have some wack perspectives about what's right and wrong, or correct and incorrect. And, most of the time, it doesn't even matter, except for how you want to come across, which is completely dependent on your audience, not some style book.
However, don't be fooled into thinking that less formal means less structured. There are now classes people can take to go over the very real and firm rules around African American Vernacular English (formerly known as Ebonics). Another fascinating dialect with similar characteristics to AAVE is Creole in the New Orleans area.
It is important to note that code-switching often involves using English that will make style-strict editors twitch. A good editor will acknowledge the code-switching involved in writing particular genres and with character POVs. If you are writing urban fiction, you probably don't want to use a formal (read: white, European, upper-class, historical) format. If you are writing high fantasy with royalty and ancient secret societies of wizards, etc, you will want a more formal writing style.
However, you also want to skew your non-dialog prose towards the formality level your target audience is familiar with. I recommend keeping the non-dialog formality level within one or two steps of the dialog of the main character(s) for consistency.
Blah, blah, blah. What could my point possibly be?
Well, because English has outright stolen borrowed so much from other languages (like Old Norse), it has rules that only apply maybe most of the time, backwards syntax, and a whole load of non-English words from literally random other languages. English is hard. Native speakers get it wrong all the time. Those with a degree in English but not linguistics get it wrong all the time. Even those who study the linguistics side of it get it wrong ALL THE TIME.
I used to joke that I used up all my language slots to be really good at English (cuz I'm not great at learning other languages despite trying... a lot). I still say it, but it isn't so much of a joke now. English is just hard.
Yet, people in the writing communities online throw hardcore shade if someone makes an error, even in a non-writerly, non-business situation. I seriously got into a discussion about whether a dangling participle was acceptable for an author in a FB post. SERIOUSLY?!?
You would think that people who know how hard the making of the words is, the people who grok the evil conspiracy of auto-correct, the people who literally spend money to correct their errors... THOSE PEOPLE would be a little more lenient about "teh" in a post someone makes about their kids driving them crazy after a day at the park.
Come on, authors! We can do better. We can be better. We can cut each other some slack and acknowledge that a dangling participle is linguistically appropriate in common vernacular. We can back up off the lack of an Oxford comma in a tweet. We can accept "gonna", "cuz", "kinda", and "prolly" as casual, easily-understood shortcuts in a world of smart phone keyboards and *instant* messages.
And sometimes, we just don't want to go back and fix the stupid little error on a social media post about kitteh wut can haz skritches. Cuz KITTEH!!