Tutorials and Unicode

Started by
2 comments, last by ExcessNeo 16 years, 5 months ago
I've been working on a series of C++ programming tutorials lately (doesn't really matter what about for this context) and I've come across an issue that I can't decide which way to go on, so I thought I'd ask the community that the tutorials will be targeted to: How should I approach unicode? A little bit of relevant background - The tutorials are of such a nature that they don't require unicode to operate. They also aren't aimed at absolute beginners but instead at people who are familiar with C++ and want to learn more about the subject. The tutorials are Windows centric (at the moment) but the Windows specific code is mostly hidden away in, and I have no real interest in teaching Windows only techniques. I'm trying to push some good programming practices in the tutorials, such as a clean class structure, namespace usage, and use of the standard C++ libraries where applicable (std::string should be your friend!). I personally would think that ensuring unicode compatibility is one of those "good programming practices", but I don't think everyone shares that opinion. So the question, once again, is how to approach unicode in the tutorials. I can see a few approaches at the moment: a) Ignore Unicode. It's a pain to use, won't benefit many users, and I don't want to deal with it when trying to learn about a different subject. b) Post an ASCII and Unicode version of all the tutorials. It's a royal pain, but gives users the option to use only what they want. c) Allow each tutorial to compile in both ASCII and Unicode. It will clutter the code somewhat, but allows the best of both worlds. (Although to tell the truth I'm not even sure if this approach is practical. Are macros like _T() cross-compiler/platform?) d) Go Unicode only. Unicode is a necessity for a flexible and long-lived code base and it will benefit the users to learn it now if they haven't. So what's your opinion? I know it probably seems like I'm obsessing over something that doesn't really matter, but fact is if I had my way I would do everything Unicode only and I don't want that to scare anyone away if it's going to be viewed as a big determent. Thanks for the input!
Advertisement
Unicode isn't relevant, unless it's the focus of the article, in the same way portable code isn't relevant unless it's the focus.

Portable/I18n compliant code is verbose, complex and even the often misses the mark, since the devil is in the details.

Tutorial teaches one single focused topic. Otherwise it becomes more than tutorial.

A car driving tutorial isn't about controlling skid on moist road at 3 degrees with certain tires. It's 1) Rotating the steering wheel, 2) pushing the pedals and 3) shifting gears. Anything else is a distraction for tutorial and becomes advanced driving guide for people who have over 10,000 miles already - or they won't benefit anything without having good grasp of basics.

Additional problem comes since you're targetting C++, which, while it does support unicode, doesn't have adequate solutions for important I18n issues.
Quote:Original post by Antheus
Tutorial teaches one single focused topic. Otherwise it becomes more than tutorial.


Well put. Thank you.

Quote:Original post by Tojiro67445
c) Allow each tutorial to compile in both ASCII and Unicode. It will clutter the code somewhat, but allows the best of both worlds. (Although to tell the truth I'm not even sure if this approach is practical. Are macros like _T() cross-compiler/platform?)


I believe mbstowcs() is the most portable function to convert to unicode, with wcstombs() the way to turn back, they are from stdlib.h. They accept input from cstrings.

On Windows you can WideCharToMultiByte() for Unicode to ANSI, MultiByteToWideChar() for the other way both can be used from just including windows.h.

This topic is closed to new replies.

Advertisement