Timeline for Sorting a list of first names from a text file
Current License: CC BY-SA 3.0
14 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Aug 3, 2015 at 20:08 | comment | added | Dan |
"Besides how are you going to sort a file without pulling it all into memory?" - that is exactly how streams work (and how your iterator works in ReadLines ). The problem with ReadLines is that it will only dispose the underlying stream if you iterate the entire file or you dispose of the iterator manually (which you probably won't do). It's not that ReadLines is bad, but you should be aware of the fact that if you don't iterate the entire file, then the resources remain open. Using a stream also better signals your intent (imo).
|
|
Aug 3, 2015 at 19:54 | comment | added | Johnbot |
@DanPantry well you're just plain wrong. Go check the reference source, ReadLines uses a StreamReader . Besides how are you going to sort a file without pulling it all into memory? Write a new exotic on disc sort? It should be in a database long before memory becomes a problem worth worrying about.
|
|
Aug 3, 2015 at 13:44 | comment | added | Dan |
One disadvantage that might earn you some brownie points with ReadLines() - not so important at 46k - is that if you increase the size of the read file much more, you're going to end up having to read the entire file in at once which might be detrimental to just loading the file into the program bits at a time (which is what a stream does). Again, for 46k - not important. 46 megabytes? definitely important
|
|
Aug 3, 2015 at 11:52 | comment | added | deworde | I would really prefer to wrap the "ToLower" and "-96" into a named sub-function, (e.g. getCharacterScore(char c)), just because it's a dirty little implementation detail which will break on edge cases. | |
Aug 3, 2015 at 11:03 | comment | added | poke | @Jodrell Yeah but we get lots of other problems too if we leave the set of those 26 letters. So I am assuming that this is an implicit restriction of the original problem. Otherwise we would need answers to questions like “what is the alphabetical position of umlauts” etc ;) | |
Aug 3, 2015 at 10:57 | comment | added | Jodrell |
@poke ToLower() works as long as we avoid Turkish or German ;-)
|
|
Aug 3, 2015 at 10:55 | comment | added | poke |
@Jodrell Good point, thanks, forgot to add a ToLower() there :)
|
|
Aug 3, 2015 at 10:55 | history | edited | poke | CC BY-SA 3.0 |
added 10 characters in body
|
Aug 3, 2015 at 10:39 | comment | added | Jodrell |
@poke be sure to use a case insensitive IEqualityComparer when looking up with the dictionary or, include all the upper case keys too.
|
|
Aug 3, 2015 at 10:28 | history | edited | poke | CC BY-SA 3.0 |
added 168 characters in body
|
Aug 3, 2015 at 10:26 | comment | added | George Phillipson | Hi Poke, thanks wish I knew that before I wrote the code, that's why I'm applying for Junior developer :) | |
Aug 3, 2015 at 10:20 | history | edited | poke | CC BY-SA 3.0 |
added 168 characters in body
|
Aug 3, 2015 at 10:12 | history | edited | poke | CC BY-SA 3.0 |
added 326 characters in body
|
Aug 3, 2015 at 10:02 | history | answered | poke | CC BY-SA 3.0 |