|
Re my performance comment, I just looked at the source for RemoveAll, and it's well written:
public int RemoveAll(Predicate<T> match) {
if( match == null) {
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
}
Contract.Ensures(Contract.Result<int>() >= 0);
Contract.Ensures(Contract.Result<int>() <= Contract.OldValue(Count));
Contract.EndContractBlock();
int freeIndex = 0;
while( freeIndex < _size && !match(_items[freeIndex])) freeIndex++;
if( freeIndex >= _size) return 0;
int current = freeIndex + 1;
while( current < _size) {
while( current < _size && match(_items[current])) current++;
if( current < _size) {
_items[freeIndex++] = _items[current++];
}
}
Array.Clear(_items, freeIndex, _size - freeIndex);
int result = _size - freeIndex;
_size = freeIndex;
_version++;
return result;
} Because it's got direct access to the underlying array, it moves as little memory as it has to. Nice - and worth using!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
There was no need of further arguments to convince me that RemoveAll() is most certainly (at least marginally) better!
I think I just... didn't think of it!
|
|
|
|
|
How about:
list.Where(x => !Remove(x));
Personally, I'd rename Remove to ShouldRemove or something, and, for the code above, invert it.
list.Where(x => !ShouldRemove(x));
or:
list.Where(x => ShouldKeep(x));
Optionally, follow up with a ToList() so the result is another list.
I rarely write loops like your original code, but save for the name of the Remove method, which doesn't remove anything, it's not weird or unreadable.
The way your co-worker managed to butcher it demands some respect though
|
|
|
|
|
I've always believed that coding is something that you have a 'knack' for. It's inherent. You either have it or you don't - and there's no point in wasting time on those that don't have it. You are never going to get them there.
The best thing you could do for your team-mate, is to explain to him that he's not very good at coding, (and probably never will be), and he should find himself a different career.
|
|
|
|
|
I posted this response to someone else in the thread, but OP might want to see it too.
--
In slight defence of the coder in question, selecting the data type that matches your data is actually good practice. eg you *can* store a date as a string;
"2020-07-22"
save it in SQL as a string, retrieve it and show it or parse it to DateTime if you need to add\remove days to it, convert back to string and save again. But we don't and I'm sure I don't need to explain why. Similarly people use decimal for currency when they really shouldn't. In the original code a List was used to process something that isn't best represented as a List, it was data used as a stack or a queue so using Queue makes that explicit. Also I don't think accessing the last item of a List using an index is very efficient.
The biggest failing in the code is obviously not just dequeuing regardless, that bit is silly and not very readable.
|
|
|
|
|
But there are going to be people approving his code and defending him.
Reminds me of a similar incident happened a few days back. I was fixing a few bugs on front end. Told this guy (Apparently my senior) I was facing 500 internal server error to which he responded 500 means bad request. You're doing something wrong.
Someone please tell him difference between error code 400 Bad Request and 500 Internal Server Error .
Anyways, I spent the next hour figuring out what was crashing on back-end so he could go and fix it.
The next day, turns out the boss was in the middle of a demo to a potential client when the crash happened. The rest was fun.
|
|
|
|
|
Yea, they did a similarly awful replacement recently.. argl.. oh well... people are nice and pay is good!
|
|
|
|
|
I'm sorry (no, actually I'm not) but the guy should be fired.
|
|
|
|
|
I wonder why they haven't many times already!
|
|
|
|
|
the madness..you guys work in a computer lab with a teacher...
Caveat Emptor.
"Progress doesn't come from early risers – progress is made by lazy men looking for easier ways to do things." Lazarus Long
|
|
|
|
|
If, somehow, I was pushed into this "team coding" thing, the other member of mine team's bones would long be vulture chewed and sun bleached.
I can do fine with someone watching to learn, or watching something so that I learn. Looking over my shoulder whilst I code?
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
The confusion started with calling it a "filter"; it's more like a garbage compactor.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Are you best suited for your job because that is the company dress code?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
That would make many of us slackers, indeed! Tying up loose ends instead of skirting the those points, would dispel rumors of anyone calling us loafers.
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
If the company dress code is "you must wear clothes", are all persons suited for the job?
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
They told me that a mask and gloves were enough to go to work. Turns out they lied, everyone else has clothes on
It does not solve my Problem, but it answers my question
Chemists have exactly one rule: there are only exceptions
modified 19-Jan-21 21:04pm.
|
|
|
|
|
I prefer to set workplace fashion trends.
Real programmers use butterflies
|
|
|
|
|
OriginalGriff wrote: because that is the company dress code? Dress code? For productive people?
You can have a dress code for the managers and the like. I don't speak to customers, so I dress "however da fuq I wants".
And yes, remembering that bitch.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I used to do that as well - ripped jeans and an obscene T, mostly. I even had written permission from one customer's board of directors to dress how I wanted on their premises (and they were a very large company).
But ... I realised that what you wear affects how you think, possibly more than you would expect. So now, even though I work from home all the time, I always wear a clean, ironed shirt, and clean blue jeans. And I think it does improve my code.
Think about it: if you were forced to work at home during the pandemic, did your attitude to work change at all on days when you booted up the PC still in your pyjamas?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Idiocy cleaned.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
modified 22-Jul-20 8:01am.
|
|
|
|
|
I was going to make a reply to OG, but I got involved in your post - clearly before the meds started to work. You can fix it up later.
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
Done, and thanks.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Other folks have commented about "dressing for work" even when working from home during the pandemic. If that works for you, fine.
For me, my work attire is a T-shirt, shorts, no shoes. I may or may not have shaved. Our meetings are generally audio-only, so that's not an issue. I'm comfortable, and my bosses have had no complaints.
My informality has no effect on my productivity. My professionalism is based on my own internal standards. One of the best things about middle-age is you no longer give a rat's ass what anyone thinks about how you look.
Software Zen: delete this;
|
|
|
|
|
I work in my PJs (scrubs, actually) until around 4pm, when I shower and change into more formal attire (shorts and Hawaiian shirt). No complaints so far, and don't anticipate any either.
/ravi
|
|
|
|
|
We have a crew of people who work in scrubs in the building. They work in our clean rooms, and scrubs are the most comfortable thing to wear underneath all the Tyvek.
Software Zen: delete this;
|
|
|
|