The difference between が and を does not stop at 私が魚を食べる kind of sentences. Though が is called the subject marker and を is called the direct object marker, there are times when they are indeed interchangeable. As to be expected, there are restrictions on when they are interchangeable.
When we learned about the potential form, we saw how が and を can be interchangeable. For instance, you can say 日本語が話せる or 日本語を話せる for "can speak Japanese." The use of を with the potential is highly tied to personal volition. The more volition the agent has, the more likely を will be used and the less likely が is used.
1. 美恵子は自然に美しい歌詞｛が 〇・を ???｝書けた。
Mieko was naturally able to write beautiful lyrics.
2. ホームラン｛が 〇・を ???｝打てた。
I was able to hit a home run.
There probably isn't a lot of people who can write this Kanji.
Aside from the potential form, there is interchangeability with ～たい and phrases of like and dislike (好き and 嫌い). To see if the same concept of control is at work, consider the following.
I've gotten to like myself.
I want to buy the latest Pokemon game.
～を分かる has traditionally been incorrect, but it first started to appear in the late 1800s and is here to stay. The trigger for why を is being acceptable is a change in perceptible control implied by 分かる.
There's no way anyone understands my feelings!
Japanese grammar generally frowns upon the same particle showing up more than once in a single clause. Consequently, counterexamples involve very specific grammatical structures that trump regular judgment calls.
If a subject that would otherwise take が is used in a potential sentence with an object marked with が, we get XがYがPotential Verb. Of course, XはYがPotential Verb exists and is most common, but the existence of the former sentence type requires explanation. In reality, we must consider five different sentence types. The least common is V, and we'll give it an ? for being questionable.
*: These sentence patterns should be thought of as underlining forms that then may change when spoken. So, in reality, as you can see later below, II is not used as is but is when the subject is marked by は.
Here is a chart that shows the percentages of what the subject is marked with depending on whether the object is marked with either が or を.
|Subject||が は に には にも||が は に にも には|
|0% 25% 8% 51% 16%||50% 49% 0% 1% 0%|
Chart Note: The subject does not like to have the same particle as the object. には and にも, which indirectly refer to the subject in terms of spontaneous action, should not be used when the object is marked with を as を highlights volition. Spontaneity is the opposite of volition. So, you'd be adding two grammatical opposites together.
There is no doubt that Type III is becoming more pervasive than Type II (remember that Type II essentially surfaces with は on the subject instead), but that doesn't help explain the difference between them at all. We will need to investigate what sort of other grammatical triggers aid in the decision. First, though, let's get back to the somewhat questionable Type V.
I can't shed a tear.
In context, questionable grammar can be made natural. With this in mind, consider the following
Man can cry, and so though I myself cannot shed tears, I have now understood the reason for crying.
Ex. 8 shows us several of the sentence types above in one, which are both frequently used in negative structures, but we do not see Pattern V. This gives us more proof to say that it is ungrammatical. The first part of this sentence lacks volition. The ability to cry is described initially as an innate characteristic of people that may in essence occur spontaneously. Thus, 涙を would be ungrammatical for this meaning. Because には calls for this sort of nuance, を becomes inappropriate.
One way to start thinking about が versus を is whether the verb is in regards to a state. So, we would expect transitive verbs like 理解する and 期待する to favor or mandate the use of が. If not, then が or を, but the internalized relationship between the parts of the sentence would be different.
Yuri can speak English.
I want to eat bread.
I want to speak Japanese.
Can you speak Japanese?
I can't explain that grammar point.
North Korea is in the state of being able to fire a missile at any time.
We will see again this concept of whether the ending is modifying the verb only or the entire phrase itself. Also, you may be wondering why を is used in Ex. 14 even though the subject is clearly in the state of being able to do the action. That is because of the next factor: control.
The next example is quite intriguing. Using が with 自分 and the like in this sort of grammar is avoided, and wrong at the worst. But, if we replace 自分 with other people nouns, the grammar doesn't change. が is highly related to spontaneity (things happening naturally), and that does help us with examples like Ex.1, but it doesn't help us here. The concept to introduce here is control. The use of を is determined by whether the speaker is able to control the action or want being expressed.
That guy is a man can deceive himself/others.
This sentence demonstrates ultimate control. The subject is able to deceive so much that he himself can be victim to his own deceit. So, there are at least two restrictions to keep in mind: spontaneity and control. The former makes が obligatory, and the latter makes を obligatory.
～ようになる & ～ようにする
Consider ～ようになる and ～ようにする. The former is intransitive and the latter is transitive. Thus, you do not see interchangeability with が and を.  will be used to show how to view the main argument to focus on in these sentences. The content of the brackets could be replaced with other phrases, but the grammar would still be the same.
I became able to naturally write Kanji while I was studying every day.
I will have (the students) able to write the Joyo Kanji by the time the fourth year students end.
18. 乃理子は独学でハングル｛が 〇・を?｝書けるようになった。
Noriko became able to write Hangul through self-study.
19. 乃理子は独学でハングル｛が ?・を 〇｝を読めるようにした。
Noriko had herself able to read Hangul through self-study.
する has a high degree of 他動詞性 even when it is in a potential phrase. This is further seen when we use する with a potential phrase with the addition of imperative or imperative-like structures such as ～なければならない or the 命令形.
20. 運転中は、絶対にスマホ｛が ?・を 〇｝使えないようにしなくてはいけない。
You must make it that you can't use your smartphone ever while you drive.
21. 引っ越しの前に、不要なもの｛が ?・を 〇｝捨てられるようにしておけ。
Before moving, have it that you are able to throw away unneeded things.
動作主性 = Agency
Another way to look at this issue is agency. Control is directly tied to a sense of agency. Whenever there is a perfective aspect and/or emphasis on result, が becomes inappropriate. Anything related to completion is really perfect for を but not が.
22. 中国に長く住んでいて、英語を話す機会がほとんどなくなったので、英語｛が 〇・を ??｝話せなくなった。
I lived in China for a long time, and because I basically lost my chances to speak English, I became unable to speak English.
23. いつでも野良猫｛を 〇・が ？｝殺せるわけではない。
You can't just be able to kill the stray cats whenever.
I'm so glad I was able to write the essay earlier than I thought.
You can't melt the icicles in that cave during the winter.
26. 量が多すぎて、ビール｛を 〇・が ？｝｛飲み干せなかった・飲み切れなかった｝。
I was unable to douse down/completely drink} all of the beer because there was just too much.
27. 山口さんがフランス語｛を 〇・が??｝話せるように、私はフランス人も招待しました。
To get Yamaguchi-san able to speak French, I also invited French people.
Sentence Note: Another reason why が wouldn't be used in Ex. 27 is the doubling of が in the same clause.
28. 神経科学試験の前に韓国語の宿題｛を 〇・が X｝してしまいたい。
I want to get my Korean homework over before my neurology exam.
29. 子供たちが来る前に、テーブル｛を 〇・が X｝片づけておきたい。
I want to have the table cleared off before the children come.
Grammar Note: The interchangeability of が and を also applies to ～たい. Here, the argument that control is the deciding factor seems really strong.
When the Potential Form and Intransitive Form Look the Same
There are instances in which the potential form of a transitive form looks just like the intransitive form. Examples of this situation include 焼ける and 割れる. So, sentences such as パンが焼ける are naturally ambiguous. The agent may or may not be implied. In this case, the meaning difference is minor. Meaning A would be for "the bread to bake" and Meaning B would be "to be able to bake bread". The solution to distinguish them would be to say パンを焼ける instead. Though one would think avoiding ambiguity would be a good thing, not all speakers like ～を焼ける because both the default intransitive meaning and the potential meaning are intransitive.
自発性 Betrays Us at Times
が is the particle for spontaneity（自発性）. It is this sense of lack of control in something spontaneous that makes が the better choice, but for verbs that typically imply a sense of control, the particle を may be seen used nonetheless due to it being the norm rather than being a reflection of the grammatical constraints of the context in question.
30. セスは日本語の天才だから、新しいレッスン｛が・を ?｝次から次にとめどなく作れた。
Because Seth is a Japanese genius, he was able create new lessons nonstop one after the other.
31. 俺はお前｛が 〇・を 〇・？｝好きで好きでたまらねーんだよ。
I like you so, so much I can't stand it.
32. 僕はきのうから豚骨スープ｛が・を ?｝食べたくて、食べたくて仕方なかったので、あの屋台に行ってみた。
I wanted to eat tonkotsu soup so bad since yesterday, and so I went to that stand.
Sure, you will have people say that ? is in fact X to them. After all, this is a grey zone. It all has to deal with how the speaker internalizes this concept of spontaneity versus control and how this relates to potential （可能）and desire （願望）. We can see how either makes sense for a lot of verbs. In the second example here, the fact that the sentence is overall more colloquial is another factor for why を may appear. The reason why が is always right in this sort of context is because of its role as the spontaneity particle.
Control ≈ Will
If you have control over something, you usually willfully exercise this control. Because of this, we will likely never see ～を聞こえる or ～を見える because not only are we dealing with completely spontaneous actions, there is no way will （有意志性） or motor action will ever be expressed with them. Spontaneous verbs dealing with the senses are completely contrary in meaning to 他動詞. Remember, grey zones like above are where the semantic domains of two things overlap. Here, we are looking at an extremity. が would have to completely disappear for ～を聞こえる or ～を見える to ever be acceptable. This is more evidence that these verbs are indeed not potential verbs despite what textbooks often claim.
This explanation also explains why ～をできる is not acceptable. Though, ～を＋する Verb can be put into the potential with the same restrictions on が・を交替, the independent verb 出来る must be treated differently.
33. 知也は英語｛が 〇・を X}出来る。
Tomoya can speak English.
34. 知也は英語｛が 〇・を X}出来るようになった。
Tomoya became able to speak English.
35. 知也は英語｛が 〇・を X・???｝出来るようになりたいと思っている。
Tomoya wants to become able to speak English.
36. 知也は英語｛が ??・を 〇｝出来るようにしたいと思っている。
Tomoya wants to have himself able to speak English.
We see again how ～ようになる and ～ようにする influence the decision and change the organization of the parts of the sentence. We expect the same things if we use ～ておく.
We ask that you prepare yourself to be able to answer the problems that you haven't been able to up till now.
We had that we cold gossip once we were in free time.
Have it that you can do the problems in the problem set used at school.
Being able to manage one's money before will become even more important than protecting one's way of life.
Have it that you can prevent youths from trespassing recklessly into the land reclamation site.
We see that ～することができる will never become ～することできる even when you add ～ておく. Aside from this, there is a lot of variation between が and を. Due to the independent nature of the verb 出来る, we can say that が出来る would still be more common and grammatically safer overall even with the addition of ～ておく.
If using ～ておく worked to get を used before 出来る, then this should work for verbs like 見える. The use of ～ようにする or an imperative phrase should also influence this.
Please make sure that the traffic signs are visible from any direction near the school zone.
The use of ～を分かる is here to stay, though it has traditionally been incorrect. Again, the idea that it is English's fault is not plausible. What is certain is that this verb has come to mean 理解する and has taken on the same grammatical rules as it in colloquial/emphatic speech.
Can we, though, find a Japanese route to the emergence of ～を分かる through this discussion? Yes, think about ～を分かろうとする. It would be harder to find Japanese speakers who don't like this example because the volitional pattern ～（よ）うとする is added, which adds the highly transitive する and 'control' related grammar. Similar grammar, then, should also make を is easier to use or at most obligatory.
43. 俺の気持ち｛を 〇・が X｝分かってくれ！
Understand my feelings!