In any case, there are good solutions for it.
Firstly, if you know from the start that you're going to open source the code, then you'll make more of an effort than (perhaps) usual to ensure that the code is well-organised, well-tested and elegant. At least within your current level of competence, but that's all anyone can hope to do in any case.
Some humility is also required in my opinion. I know many people subscribe to a fake-it-until-you-make-it philosophy, and there's some value in that, but when it comes to open sourcing your code, it's good to check your ego and to be open to suggestions and criticism. There will always be people who are more knowledgeable and better than you at certain things. Best IMO is to accept this (and their criticism if you're lucky enough to receive it) and to see you how can learn from them and improve.
BTW, I speak from some experience. I have had some nominally embarrassing experiences with OSS where other people highlighted relatively obvious security issues with code that I wrote and which I thought was of high quality. However, in turn I got free QA from knowledgeable people and in the process the code improved further as I fixed the problems.
Also, as some people have mentioned already. OSS that is popular gets improved all the time. I.e. if you're lucky, and your code doesn't languish in obscurity, then you'll get patches and pull requests to improve your code.
So the way out of the dilemma... if you're really just being held back because you fear criticism and ridicule, is to ignore the fear, be humble, and to still open-source (perhaps after doing some cleanup, but not to the extent that you use it as a crutch to avoid open-sourcing).
You'll probably realize that the fear was totally unfounded or in the least exaggerated.