Understanding the Problem
I think you need to consider several key points here, the first and most important is what the issue actually is with this older employee. Perhaps he really is just incompetent and is simply a hindrance, perhaps he is indeed an expert but is short tempered and poor at communicating (something I have seen in far too many 'experts') and as such is less useful as a mentor.
It may help if you can find a little about this employee's history, if he previously acted solely individually and never had any management or team experience he may just not know how to work in a team.
It is also possibly you are struggling to communicate with him yourself, you have presumably recently left education (given this is your first job) and it is not at all uncommon for younger workers to have remarkably different norms to those who have been in industry for a long time.
How to Cope With the Situation
Now, once you have considered all these points we move onto how you can cope with these issues. Now it seems to me that in your actions you are very much making yourself accountable to consequences if anything goes wrong, this is quite possibly a poor idea, particularly if you think there is unlikely to be much success working with this person.
Instead, at least for now it would be better to submit to his 'ideas' despite how much you may disagree with them, but make sure to keep a fastidious record of both your communications with him. If he asks you to recode something as you gave in your example, do not object, simply say, "Do you think we can still meet our deadline for this project if I do that?" This puts a great burden on him as if after ignoring you the project is indeed late he will be completely responsible, being the more senior staff member and having been warned.
It is also a good idea to ask him before making significant decisions, if you are worried about being ignored phrase it like: "I just wanted to get your go ahead, I was thinking of using library X for this task but if you dont think it is a good idea please give me some advice on how you would approach this." This also puts more responsibility on him should things go wrong, it may also have the side effect of causing him to respect you more if he feels you are asking him for sensible advice.
Some Points of Advice
I will emphasize this now, keep all your communication to email if at all possible, this is more formal and is fully audit-able in case this becomes a full dispute or grievance later. You want good records so the older more respected employee cant pull the trust and respect card with your boss later to overrule your word.
The aim to my advice is that we achieve one of two results, either, if he is indeed an expert and his advice pans out in the long run perhaps you will learn from him and become more able to work with him. However if things do not go so well this employee will be discredited to your boss as he, being more senior and in a position of leadership let the project fail, you will probably not be help accountable as you were under his instruction, as long as you do as he advises and do not try and undermine the older employee (this allows him to blame any failure on your insubordination).
Either way, you will gain respect from your boss for trying to work well in a team weather is ultimately succeeds or not and he is far more likely to give you more independence in future, the older employee will also be shown for what he is, either a true expert, or simply someone with more confidence than skill.