Comments (3)
On Mon, 27 Jun 2011, Qbit86 wrote:
Why do you use deprecated out- and ref-parameters to return values?
This is a good idiom in imperative code. In functional code it
obviously is a bad idea.
Peter
from c5.
This is a good idiom in imperative code. In functional code it obviously is a bad idea.
But my C#-code is as functional as possible :) And out/ref + assignments are too imperative :(
You say: «The design has been influenced by the collection libraries for Java and Smalltalk and the published critique of these.» (http://www.itu.dk/research/c5/latest/ITU-TR-2006-76.pdf) It's probably worth looking at collection libraries in mixed-paradigm languages as F# (http://msdn.microsoft.com/en-us/library/ee353413.aspx).
Exception-free search operations always return option as zero-or-one-element collection (in Haskell they return Maybe monad):
http://msdn.microsoft.com/en-us/library/ee353739.aspx
http://msdn.microsoft.com/en-us/library/ee353786.aspx
etc.
It's very handy (even if one cannot use pattern matching in C#): you don't need to divide initialization into declaration and assignment; your locals are immutable, their values are predictable. Compare current usage with suggested:
// 1)
K key = ...
K actualKey = key;
V value;
if (dictionary.Find(ref actualKey, out value)) { /* Use actualKey, value. / }
// 2)
K key = ...
KeyValueOption<K, V> result = dictionary.Find(key);
if (result.HasValue) { / Use result.Key, result.Value. */ }
In C++ STL we've got similar pattern: get result handle (iterator—Option), compare it with sentinel (v.end()—Option.None), retrieve it from handle (dereferense—Option.Value).
Class Option can be implemented as in Elevate Library (http://elevate.codeplex.com/), for eaxmple.
from c5.
Agreed the Option type of F# is a very neat solution.
However, C5 also tries to mimic the standard C# interfaces and programming styles and here the so called Try Get pattern is most often used. Cf. Krzysztof Cwalina, Brad Abrams: Framework Design Guidelines: Conventions, Idioms, and Patterns for Reusable .NET Libraries (http://www.amazon.com/Framework-Design-Guidelines-Conventions-Development/dp/0321246756).
C5 is currently littered with Try Get and it would be an enormous undertaking to convert these into Option type style - and also be a major breaking change it the old Try Get methods were not to remain in the library.
from c5.
Related Issues (20)
- Traversal algorithm should be part of this kind of library
- Latest nuget package is built in debug mode HOT 1
- Unecessary allocations in HashSet<T> HOT 6
- Documentation diagrams not generated correctly HOT 1
- Is this project still being maintained? HOT 4
- Why does TreeSet not implement SCG.ISet? HOT 3
- Inconsistent/wrong implementations of Keys property by guarded dictionaries HOT 1
- Nuget NetStandard/Core Update HOT 4
- Add AppVeyor CI for PR validation to this project HOT 1
- Doesn´t work on Visual Studio 2015 HOT 2
- Error at building project C5 in Visual Studio 2017 15.1 26403.0 Enterprise HOT 1
- State of project? HOT 10
- Time complexity of SortedArray<t> indexing HOT 1
- Single writer multiple readers pattern with snapshots HOT 2
- Inconsistent default constructors HOT 5
- compatibility with Unity HOT 7
- Add range variants of FindMin() and DeleteMin()
- Any modern documents? HOT 2
- Please update package on NuGet HOT 4
- TreeList<T>? HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from c5.