The author seems to believe this code is unreadable and will cause problems a few months down the road:
The author seems to believe this code is unreadable and will cause problems a few months down the road:
Did I mention that sometimes I over-think things?
Did I get his last example right?
The author seems to believe this code is unreadable and will cause problems a few months down the road...
if Gender <> 'M' then continue; if Age <= 18 then continue; if Age > 65 then continue; if Name = '' then continue;
Well, yes, as usual hype, but sometimes it's funny.
For example, how would you solve such a problem?
...
ולכשתשכלו;BB;AA;CCC;MMM;AAA;MeeM:ABA;AABB;ABBA;BAAB;MAN;NAM;MAM;NAN;FAT;BAAB;FAAF;باب;文言文
I'm waiting for that ah-ha moment when I can start to figure out really simple things.... Every piece of documentation I can find seems to say this should work, yet I get a compilation error. I feel dumb for asking, but why doesn't this work? Is there some compiler directive I have to give to let this thing do anonymous functions?
SymbolicFrank
What is the problem that anonymous functions solve?
One deficiency I admit I hope it wasn't there in the first place. It's a rare condition, but once you're trapped in, you might not realized where the problem is.
function IsNegative(SomeParam: Integer): Boolean; var SomeVar: Integer; function Calculate: Boolean; begin Result := False; if SomeVar < 0 then Result := True; end; begin Result := Calculate; end;
With the appropriate helpers, I think the original code boils down to (not tested):
procedure TForm1.Button1Click(Sender: TObject); var &Word: String; begin LastWord := ''; for &Word in lowercase(Memo1.Lines.Text) .Split([#9, #10, #13, ' ', ',', ';'], TStringSplitOptions.ExcludeEmpty) .Sort // could be a normal function, "for word in sort(memo....split) do" do begin If &Word = LastWord then continue; LastWord := &Word; if (&Word.Length <=2) or (&Word <> ReverseString(&Word)) then continue; Memo1.Append(&Word); end;
IMHO: Ugly, with all that is going into the for loop header....
Lately I had to rewrite 'functional' programming because it was slower than a traditional for loop.That's actually one core principle of (pure) functional programming: immutable objects. That's why (almost?) every functional programming languages are garbage collected.
The main problem is if you have a big array (100k objects) and what is being done in each .something.something you concat is to create a new array!!! Of course array of pointers but nevermind, it was slow and I get the same result with more lines of code but faster.
So think twice when one liners are best or not... Measure their speed.
Lately I had to rewrite 'functional' programming because it was slower than a traditional for loop.
The main problem is if you have a big array (100k objects) and what is being done in each .something.something you concat is to create a new array!!! Of course array of pointers but nevermind, it was slow and I get the same result with more lines of code but faster.
So think twice when one liners are best or not... Measure their speed.