It's returning an IEnumerable using yield. The caller would take out the ones they need. There's no sense in passing parameters like limit as it would the the callers' responsibility to get only the number they need. IEnumerable won't trigger data access until and unless the data is required and so the limit parameter doesn't have any use.
This might be personal preference but I really don't like methods exposing tuple types. Create a type (possibly a struct) that has carries some semantics instead of the tuple.
Note that this in C#, this would obviously not be my thoughts if the language was F#, Haskell, Erlang or any other functional language.
Yeah now that I've thought it through, I'm unsure why I even said that. I read something like this on someone's blog recently and haven't had time to process it.
What I do in order to use the ease of tuples and other complex generic types, and get readable code, is to at least give them a friendly name by utilizing the using statement of C#.
In a specific context, you can also give the type friendly method names (like e.g. Ruby's alias methods) by using extension methods that are just simple pass-throughs.
Comment preview
Comments have been closed on this topic.
Markdown formatting
ESC to close
Markdown turns plain text formatting into fancy HTML formatting.
Phrase Emphasis
*italic* **bold**
_italic_ __bold__
Links
Inline:
An [example](http://url.com/ "Title")
Reference-style labels (titles are optional):
An [example][id]. Then, anywhere
else in the doc, define the link:
[id]: http://example.com/ "Title"
> Email-style angle brackets
> are used for blockquotes.
> > And, they can be nested.
> #### Headers in blockquotes
>
> * You can quote a list.
> * Etc.
Horizontal Rules
Three or more dashes or asterisks:
---
* * *
- - - -
Manual Line Breaks
End a line with two or more spaces:
Roses are red,
Violets are blue.
Fenced Code Blocks
Code blocks delimited by 3 or more backticks or tildas:
```
This is a preformatted
code block
```
Header IDs
Set the id of headings with {#<id>} at end of heading line:
## My Heading {#myheading}
Tables
Fruit |Color
---------|----------
Apples |Red
Pears |Green
Bananas |Yellow
Definition Lists
Term 1
: Definition 1
Term 2
: Definition 2
Footnotes
Body text with a footnote [^1]
[^1]: Footnote text here
Abbreviations
MDD <- will have title
*[MDD]: MarkdownDeep
FUTURE POSTS
Partial writes, IO_Uring and safety - about one day from now
Configuration values & Escape hatches - 5 days from now
What happens when a sparse file allocation fails? - 7 days from now
NTFS has an emergency stash of disk space - 9 days from now
Challenge: Giving file system developer ulcer - 12 days from now
And 4 more posts are pending...
There are posts all the way to Feb 17, 2025
RECENT SERIES
Challenge
(77): 20 Jan 2025 - What does this code do?
Answer
(13): 22 Jan 2025 - What does this code do?
Comments
It's returning an IEnumerable using yield. The caller would take out the ones they need. There's no sense in passing parameters like limit as it would the the callers' responsibility to get only the number they need. IEnumerable won't trigger data access until and unless the data is required and so the limit parameter doesn't have any use.
An endId and limit seem at odds with one another.
Ashic,
Yep!
James,
startId: 1
endId: 100000
limit: 100
I'd change it to IEnumerable <dictionary<int,jsondocument>
Oh no, damned HTML. Again:
I'd change it to IEnumerable<Dictionary<int,JsonDocument>> I think key-value dependencies are better handled using Dictionary. Any ideas?
Chojrak,
It isn't key value. It is a tuple, it isn't a set of int to json doc, it is a int & json doc.
This might be personal preference but I really don't like methods exposing tuple types. Create a type (possibly a struct) that has carries some semantics instead of the tuple.
Note that this in C#, this would obviously not be my thoughts if the language was F#, Haskell, Erlang or any other functional language.
Is the collection between the startId and endId not continuous? A limit would make sense then.
James,
Yes, the collection may not be continuous
Patrik,
This is mostly for internal API needs, it just doesn't make sense to create a type here, it wouldn't add enough meaning
Is it not also bad practice to publicly expose IEnumerable for methods like this ?
Andrew,
I disagree with that quite strongly
Yeah now that I've thought it through, I'm unsure why I even said that. I read something like this on someone's blog recently and haven't had time to process it.
When using 'yield' the resulting items will be returned 'lazily' (delayed execution).
This might not be what the method is intended to do. I think the intention is to have the results ready after the call.
It also might have potential issue when the underlying data store is closed and the enumeration gets executed.
Cheers,
Dmitriy,
@Patrik,
What I do in order to use the ease of tuples and other complex generic types, and get readable code, is to at least give them a friendly name by utilizing the using statement of C#.
An example is given on my blog: http://goo.gl/ksCm
In a specific context, you can also give the type friendly method names (like e.g. Ruby's alias methods) by using extension methods that are just simple pass-throughs.
Comment preview