Click here to Skip to main content
15,895,837 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Apple slips in sales ranking - again. Pin
abmv18-Jul-21 8:40
professionalabmv18-Jul-21 8:40 
GeneralRe: Apple slips in sales ranking - again. Pin
OriginalGriff18-Jul-21 8:44
mveOriginalGriff18-Jul-21 8:44 
GeneralTypescript optimisation benchmarks Pin
Chris Maunder16-Jul-21 6:17
cofounderChris Maunder16-Jul-21 6:17 
GeneralRe: Typescript optimisation benchmarks Pin
PIEBALDconsult16-Jul-21 7:56
mvePIEBALDconsult16-Jul-21 7:56 
GeneralRe: Typescript optimisation benchmarks Pin
Chris Maunder16-Jul-21 10:32
cofounderChris Maunder16-Jul-21 10:32 
GeneralRe: Typescript optimisation benchmarks Pin
PIEBALDconsult16-Jul-21 11:35
mvePIEBALDconsult16-Jul-21 11:35 
GeneralRe: Typescript optimisation benchmarks Pin
Chris Maunder16-Jul-21 16:13
cofounderChris Maunder16-Jul-21 16:13 
GeneralRe: Typescript optimisation benchmarks Pin
Gary R. Wheeler16-Jul-21 10:37
Gary R. Wheeler16-Jul-21 10:37 
PIEBALDconsult wrote:
I say use for or while whenever you can and only use foreach as a last resort, when the others don't work. foreach has serious limitations, as do its proponents.
Obligatory xkcd: Optimization[^]

My experience with foreach is from C# rather than TypeScript, but would think the same reasoning applies. For me the choice of foreach vs. for (...) is based on whether I care about the state of the iteration within the loop or not. If I don't, then foreach is preferable. If I do, then either for (...) or while (...) wins. The construct being iterated over plays a role as well. If it's a simple array or an array-like class, then for (...) gets a stronger weight in the voting. If the only way to iterate is through IEnumerable or something similar, then I'll almost always use foreach. The goal for the decision is to choose the simplest, most natural iteration method based on the needs at the time.

As far as performance goes, I would think it doesn't matter in most cases. If you find a case where the enumeration technique dramatically affects performance, I'd be inclined to rethink the algorithm.
Software Zen: delete this;

GeneralRe: Typescript optimisation benchmarks Pin
PIEBALDconsult16-Jul-21 11:25
mvePIEBALDconsult16-Jul-21 11:25 
GeneralRe: Typescript optimisation benchmarks Pin
Gary R. Wheeler16-Jul-21 13:43
Gary R. Wheeler16-Jul-21 13:43 
GeneralRe: Typescript optimisation benchmarks Pin
honey the codewitch16-Jul-21 13:00
mvahoney the codewitch16-Jul-21 13:00 
GeneralRe: Typescript optimisation benchmarks Pin
Jacquers16-Jul-21 20:58
Jacquers16-Jul-21 20:58 
GeneralRe: Typescript optimisation benchmarks Pin
BillWoodruff16-Jul-21 22:31
professionalBillWoodruff16-Jul-21 22:31 
GeneralRe: Typescript optimisation benchmarks Pin
theoldfool17-Jul-21 0:47
professionaltheoldfool17-Jul-21 0:47 
GeneralRe: Typescript optimization benchmarks Pin
BillWoodruff17-Jul-21 2:12
professionalBillWoodruff17-Jul-21 2:12 
GeneralRe: Typescript optimisation benchmarks Pin
Gerry Schmitz17-Jul-21 6:35
mveGerry Schmitz17-Jul-21 6:35 
GeneralThought of the Day Pin
OriginalGriff16-Jul-21 4:21
mveOriginalGriff16-Jul-21 4:21 
GeneralRe: Thought of the Day Pin
Richard Deeming16-Jul-21 4:56
mveRichard Deeming16-Jul-21 4:56 
GeneralRe: Thought of the Day Pin
PIEBALDconsult16-Jul-21 4:58
mvePIEBALDconsult16-Jul-21 4:58 
GeneralRe: Thought of the Day Pin
OriginalGriff16-Jul-21 6:01
mveOriginalGriff16-Jul-21 6:01 
GeneralRe: Thought of the Day Pin
Slow Eddie16-Jul-21 8:58
professionalSlow Eddie16-Jul-21 8:58 
GeneralRe: Thought of the Day Pin
Daniel Pfeffer16-Jul-21 5:03
professionalDaniel Pfeffer16-Jul-21 5:03 
GeneralRe: Thought of the Day Pin
W Balboos, GHB16-Jul-21 8:44
W Balboos, GHB16-Jul-21 8:44 
JokeThings to think about Pin
Mike Hankey16-Jul-21 3:21
mveMike Hankey16-Jul-21 3:21 
GeneralRe: Things to think about Pin
PIEBALDconsult16-Jul-21 3:27
mvePIEBALDconsult16-Jul-21 3:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.