#Useless command line application that sorts a string (or a file) by alphabetical order

1 messages · Page 1 of 1 (latest)

left terrace
#

@limber ice this was the thing I told you about

regal kernel
#

A few issues imo:

Why are you casting literally every statement to (void)? It provides no benefit whatsoever (from what I know) but adds unnecessary noise to the code.
And I don't know any style guide that would recommend this and it's usually a good idea to follow a popular style guide as that makes it easier for others to read your code without getting used to your style.

Your lexicalAnalyser function takes a reference to a flags int, why not just return one? Output parameters are rarely a good idea if you can avoid them.

You use bit flags for knowing which flags haven been passed which is reasonable but please define constants instead of using magic numbers. A macro or function that does the bit manipulation would probably be helpful as well.

left terrace
#

The rest i'll probably do it later

limber ice
#

very interestring

regal kernel
left terrace
# regal kernel Whe even for ternaries?

Ternaries are expected to have a return value, so if I use it to print to stderr, I want to make sure that I explicitly know that it is not meant to print to stderr and return to a variable

#

Er, by ternary, i mean things like

#

Condition?std::cerr<<"error message",1:0;

regal kernel
#

Honestly if your ternaries have side effects like that then don't use a ternary.

#

Use an if-else instead

left terrace
#

What is a good way to check if a string fails to allocate memory?

regal kernel
#

Which way do you allocate it?

left terrace
#

I should swap to dynamically, especially since it's allocated only once, but that's besides the point

#

There's a hard limit on std::string length, so if I ever hit it, do I just throw an error message and exit?

#

Now it's dynamically allocated and will probably crash

left terrace
#

It's now back to statically allocated because there really isn't a reason to dynamically allocate a local var anyways

regal kernel
#

If you do malloc you should check if it returns a null pointer. If you use new or stdd::string it throws a bad_alloc exception

left terrace
#

But I wasn't asking about memory allocation, sorry for the confusion, but memory reallocation

#

There's a hard maximum on the size of an std::string, so how do I know if it hits that limit?

#

I think it throws an std::length_error, based on reading the stl source code, but I'm not completely clear

winged wolf
#

I was going to say this is literally sort

#

but no

#

it's so much less useful lmfao

#

I love it

left terrace
#

Why would I make something useful?

#

What does sort even do anyways?

#

Sort the lines in a file in alphabetical order?

winged wolf
#

yeah

#

or numerical based on the first number