Sort of related. Why would any one use a comma as a delimeter? Pipe people, pipe.
Depending on the font, pipes can be confusing. I also find pipes make it hard to read things unless combined with a leading and trailing space " | ".
There’s a good chance you’re correct.
Of course it is. Only Haskell psychopaths would think “intercalate” is a better word than “join.”
Their campaign slogan “intercalate us” was a miserable failure, true.
I admit I’d never heard “intercalate” used before I learned Haskell. Apparently it’s a term of art in molecular biology and in whatever -ology studies the Hebrew calendar. Join has another meaning in Haskell:
join :: Monad m => m (m a) -> m a
Example in the list monad:
join [[1, 2, 3], [4, 5, 6]]
Result:
[1,2,3,4,5,6]
i.e. collapses nested linked lists into a single linked list.
These two. If you’ve ever had to maintain someone else’s code, you will bless comments and curse code-compactness.
We used to apply a “that’s cool” test to code during walkthroughs - if that phrase was uttered, the code was rewritten to be clearer (or at least heavily commented).
I remember C being described as a “write-only” language (as opposed to COBOL being “read-only”, IIRC).
Usually I only ever have to build a comma separated list for logging, so it would look something like:
if(numItems > 0)
{
cout << item[0];
for(i=1; i<numItems; ++i)
{
cout << ", " << item*;
}
cout << endl;
}
No need to check if you’re the first item every iteration of the loop, and no trailing comma to strip off. Yeah you’re duplicating code, and normally I hate doing that, but in this case I think it’s more readable as to what’s going on. The first item is treated differently. This also works for a single item list.
That’s how I usually do it. After you exit the loop trim off the trailing comma.
It is very important to filter the raw content of data block by replacing non-ALPHA NUMERIC like “,” the comma with a blankor space. The Data field will then be accurate. Create output files outputs: Number of Records should match especially based on index field. Fieilds with expected content like why blank not a zero value. People’s name with numbers. Unless you have a fixed data block size you will problems with commas in dollar amounts.
That depends on how you’re representing dollar amounts. If you’re storing them as numbers, rather than strings, they you shouldn’t even be using commas in dollar amounts. You should let the display interface put in things like commas and dollar signs. If you do want to store them as strings with commas for some reason, or if you have commas in other text, you can quote the entire string or use an escape character before the commas.
If this is a one shot assignment… I would use a freeware EDXOR.
Very fast like DOS http://members.ozemail.com.au/~nulifetv/freezip/freeware/
To use: Select ALL then FORMAT then WIPE ->NON-ASCII plus others.
Do not select WORD WRAP on EDIT option (if do not see full width. Use the bottom bar-- it has no limit!!)
Save it as text by adding “.txt”. Open this file from Ms Excel file import. The conversion is flawless…
Comments are biodegradable and eventually decompose into lies. They are for explaining stupid things that you have no control over, not for explaining code that ought to be self-explanatory.
i <3 u.
Code is crap. Comments are the place to clearly explain an algorithm. A properly commented block of code can be re-written in less time than it takes to identify and fix a bug in it. Some of the worst problems come from assuming that the code represents the way something is supposed to work, causing an original error to propogate long after it is created. If the comments fail to reflect changes to code over time, then programmers are doing their jobs, and usually their managers as well.
A number of the example above use a constant value like -1, as a general rule any constant in code should be seen as a red flag. If you find yourself using a constant, take a step back and you can usually find a better way to do it.
Constants are not always bad, though I would strongly argue in THIS case where you are doing a -1 or +1 or such they are pretty much always bad.
If I can’t read and understand your code as easily as I could read a book, without comments, I would say you need to work on your coding skills. I love comments, use them a lot, but, never, ever, in place of readable code.
I agree code should be clear and readable. But it is too terse to incorporate every detail to take into consideration. This problem is bad enough when a variable is used which may have last been set far from the current line of code, and the problem can become a disaster with polymorphic objects. The class of the object is obscure from it’s reference, and comments are necessary to convey it’s potential content.
What you are describing is what I often refer to as ‘code hiding’. It can happen for many reasons but the most common is people feeling too strong a need to remove repetitive code to a function. This need (taught to them with good intentions) can lead to hiding structure, and structure should never be hidden even if it is repetitive.
Object oriented programming can really amplify this problem.
A (simplified) example. There is an object called car. Someone decides that instead of calling Car.start then Car.move then Car.stop, they will just create a method called Car.do.
Now the next programmer reading the code has to dig an extra layer deep to see what the heck the Car object is actually doing.
Add some more code hiding (other objects usually) within the Car object and now the poor programmer is digging three levels deep to find out what should have been obvious from a quick glance at the first level of code to begin with.