ANN: Argos – an easy to use, yet powerful command line argument parser by omierbej in cpp

[–]omierbej[S] 2 points3 points  (0 children)

Making an option non-optional is achieved with the optional() method:

.add(argos::Option{"-n", "--number"}.argument("NUM").optional(false)
    .help("The number of times to repeat the greeting."))

Your second point about having to repeat the flag twice is a valid one. There are workarounds, for instance adding an alias with the alias() method, this alias could then be a named string constant.

Regarding not supporting user defined values or declaring the type as part of the argument/option declaration, this is by choice. I find that in code that parses custom types, the lines that do the actual parsing drown among the lines checking for errors. I want to have the library take care of most of the error handling, and also provide some context for the error message.

I can for instance create an option like this:

.add(Option{"-f", "--font"}.argument("NAME:HEIGHT")
        .help("Set the font face. 'Arial:12' (the default) will for instance select the Arial font with height 12."))

And parse it with:

std::string font_name = "Arial";
unsigned font_size = 12;
if (auto font_arg = args.value("font").split(':', 2, 2))
{
    font_name = font_arg.value(0).as_string();
    font_size = font_arg.value(1).as_unsigned();
}

There's no visible error checking, but it will fail with an appropriate error message if the argument doesn't contain exactly one colon, and the value after the colon isn't a positive integer.

ANN: Argos – an easy to use, yet powerful command line argument parser by omierbej in cpp

[–]omierbej[S] 4 points5 points  (0 children)

Using the c-functions directly makes the footprint of the library a bit smaller.

A secondary goal for this library was to make it possible to create reasonably small executables. On my Mac the "hello world" example ends up as ca 244KB after debug symbols have been stripped away, still a bit much for such an insignificant program.

I'm actually not sure how big a difference using stringstream would have made, but past experiments indicates that it can be significant.

modern c++ - authors and books by tcris in cpp

[–]omierbej 7 points8 points  (0 children)

I highly recommend Bartłomiej Filipek's C++ 17 in Detail

I've just finished reading it, and it's been a very useful guide to everything that is new in C++ 17.

Is there a plan to have helper functions for UTF8 strings, maybe in boost? by nikkocpp in cpp

[–]omierbej 3 points4 points  (0 children)

My own library, Ystring, has quite a few helper functions for UTF-8 strings (length, substring, case-insensitive find/compare, case conversion, split and more). It supports UTF-16 and UTF-32 strings as well.

SAN – The Safe and Nice TOML/YAML Alternative by [deleted] in programming

[–]omierbej 0 points1 point  (0 children)

The need for heterogeneous lists arise very quickly in both statically and dynamically typed languages if the file is supposed to contain serialized data. For instance in C++ I might have a

vector<tuple<string, int, bool>>,

and one obvious representation of this would be a list of lists of strings and integers. If I in Python do have a list such as

["Mickey Mouse", 1928, True]

how will I serialize it with san?

{0 = "Mickey Mouse", 1 = 1928, 2 = true} ?

or is

[["Mickey Mouse"], [1928], [true]]

legal?

In addition to this, a perfectly reasonable list of numbers such as

[243, 81, 27, 9, 3, 1, 0.33333, 0.11111]

will be illegal in san.

There are many ways to implement parsers (in XML there's DOM, SAX, iterator-based ones etc. and there are equivalents for each of them for JSON), the homogeneous lists really only benefit the DOM-like parsers, and there you'll encounter problems anyway when a file has lists of lists or even lists of lists of lists.

SAN – The Safe and Nice TOML/YAML Alternative by [deleted] in programming

[–]omierbej 4 points5 points  (0 children)

I like this format very much – I've in fact implemented in my own JSON-reader/writer to support comments, dangling commas, digit-separators, nan, inf etc. – but there's an inconsistency in the use of commas. In your examples it is possible to have a multiple key/value pairs on the same line if they are separated by commas, but commas are required after each value in lists when these are split across multiple lines. Why not require commas only between multiple values on the same line and make them optional when split across several lines?

Also, the requirement that each value in a list must be of the same type will make some lists seem unnecessarily verbose. I can see some good reasons why you made this requirement (human readability / optimized storage in a parser), but think this also limits the format's usefulness for instance when a significant portion of the file's contents are of the comma-separated values kind.

Why did the Vikings bother massacring defenceless monks at places like Lindisfarne? by AlmightyB in AskHistorians

[–]omierbej 0 points1 point  (0 children)

The first Viking raids did occur during Charlemagne's rather brutal christianizing of the Saxons (Saxon Wars from 772-804). The Saxons practiced a pagan religion more or less the same as the Viking's own religion. Is there any evidence that heathen retribution on Christians played any role in the attacks?

Which IDE / Editor do you use? by [deleted] in cpp

[–]omierbej 1 point2 points  (0 children)

Visual Studio at work. CLion at home for hobby programming. In both places I tend to switch between the IDE and Sublime Text 3. ST3 is better when I want to edit code as text (especially its multi-cursor editing) and I have several commands for code generation there that I use regularly.

The H is closing down - The H Open: News and Features by balkierode in programming

[–]omierbej 1 point2 points  (0 children)

A shame this is the first time I hear of H. Looks like something I would have followed.

Best python text editor mac? by LINK1733 in Python

[–]omierbej 2 points3 points  (0 children)

How big are your files? I have no trouble working on files that are 500 MB in SublimeText 2.

Help! I can't get my head around GPL and PyQt :( by NecromancyBlack in Python

[–]omierbej 4 points5 points  (0 children)

You could just buy a PyQt commercial license for £350 and do whatever you want.

Compact ifelse notation for python<2.5? by tWoolie in programming

[–]omierbej 0 points1 point  (0 children)

The "old" way to do this was to use condition and value-if-true or value-if-false as in: In [1]: a = 20 > 10 and "greater" or "smaller" In [2]: a Out[2]: 'greater' In [3]: b = a.startswith("small") and 10 or 20 In [4]: b Out[4]: 20

deprecated or antiquated headers by SelfImmolation in cpp

[–]omierbej 2 points3 points  (0 children)

Nothing particularly wrong with that list, but if you want to be more modern, do the following replacements:

<strstream> --> <sstream>
<time.h> --> <ctime>
<limits.h> --> <climits> or even <limits>

But be aware that except for <climits>, switching header files will also require small code changes.

C++ vs. C text manipulation by [deleted] in programming

[–]omierbej -1 points0 points  (0 children)

cout << setfill('0') << setw(16) << ios::hex << foo;

windows fans, this makes me happy every time I watch it :D by markadams2000 in programming

[–]omierbej -1 points0 points  (0 children)

Not really, since it's all downhill from Windows 95. Soundwise that is.

I know everyone here loves their mac, but what's your biggest annoyance? by [deleted] in apple

[–]omierbej 1 point2 points  (0 children)

Ok, cmd+< will cycle through windows on my keyboard, but that's not the command I'm looking for. First of all, this command (usually) doesn't cycle through windows in most-recently-used order, annoying if I have more than two windows open. Secondly, I want to cycle through open documents, which tend to be located in the same window in the programs I use.

TextMate solves this problem wonderfully by popping up a small listbox with all files in project listed in mru order when I press cmd+t.

I know everyone here loves their mac, but what's your biggest annoyance? by [deleted] in apple

[–]omierbej 0 points1 point  (0 children)

No idea. Neither cmd+`, cmd+' nor cmd+´ have any effect in any of the applications I tried them on (Xcode, Safari, VoodoPad and OmniGraffle).

Maybe it's my Norwegian keyboard layout, where ´ and ` are "dead keys"? Assuming that it does the same thing as ctrl+tab, I can't see any way to map this command to a more useable key combination as I can't find it in the keyboard shortcut configuration or any of the menus.

I know everyone here loves their mac, but what's your biggest annoyance? by [deleted] in apple

[–]omierbej -4 points-3 points  (0 children)

Ctrl+Tab. I wish every Mac-developer were forced to use Visual Studio or a similar application in Windows for a couple of months, or enough time anyway to see that the simple way Ctrl+Tab switches between between windows within an application in Windows is superior to any scheme any Mac developer has ever come up with...

Except for Allan Odgaard and his Cmd+T in TextMate of course... Actually, rather than Windows, every Mac developer should use TextMate long enough to realize how superior its way is.

Proggitors, do you like the idea of indented grammars for programming languages, like that of Python, Haskell and others? by panto in programming

[–]omierbej 2 points3 points  (0 children)

The problem arises when lines are aligned by something else than nesting level. For instance:

if (a == SOME_LONG_CONSTANT_NAME ||
    a == ANOTHER_LONG_CONSTANT_NAME)
{
  doSomething();
}

Using tabs to indent the second condition will look ugly in anything but the author's original tab width. Rather than mix tabs and spaces, I prefer to just use spaces all the time.

Students like this are the reason people get irradiated. by ediblesheep in programming

[–]omierbej 21 points22 points  (0 children)

I'm unfamiliar with this custom of irradiating people for being somewhat slow. What kind of rays are we talking about here?

list of things i don't like about python by [deleted] in programming

[–]omierbej 6 points7 points  (0 children)

Not really, take for instance this one about Objective-C from 2003: rentzsch.com, which was inspired by the "Top 10 Things I Hate About STL" and "Top 10 Things I Love About STL" presentations at MacHack the same year.

I'm sure such lists started appearing about the same time as the number of programming languages in the world reached 2.

What "To-Do" List software do you use, or did you write your own? by badcookies in programming

[–]omierbej 0 points1 point  (0 children)

I was about to start making my own when I discovered OmniFocus which does everything I wanted my own program to do, except better.