I hate it when I am too clever for my own good...
-
Everyone has their own workflow that's best for them. That said, a lot of my team members make copies of working files, rather than use source control as a tool. I work with one guy who tends to keep everything checked out, and only checks in prior to doing a build for distribution. It drives me nuts, because he'll have days or even weeks worth of work that exists only on his machine (our source control data base gets backed up daily). I'm tempted to power off his machine and substitute a bad hard drive to teach him a lesson :( . My approach, at least in our development branches, is to work incrementally and check-in each successful increment. Most of the time I make the feature I'm working on disabled/invisible/inactive in release builds, until I think it's ready. This makes backtracking, which I do a lot more than I'd like to admit, simpler. Diff's are handy too when I've led myself down the proverbial garden path :sigh:.
Software Zen:
delete this;
Gary Wheeler wrote:
Everyone has their own workflow that's best for them.
Very true. It's a fine balance, I think: I don't like a checked in version that won't run, or throws continual NotImplementedExceptions, and I try to avoid thinking of version control as a backup system! :laugh: Instead I have my NAS and automatic incremental backups that I don't even see, much less think about. I can understand both you and your team member's position: he doesn't want to issue code that he isn't sure is final in case it gets used and has to become final by default. But you want it backed up so weeks can't be lost... Perhaps a "proper" backup system for your PCs to work alongside the SVN/GIT route would be useful? I know damn well I wouldn't want to have to rebuild my current PC without good backups - it would take me days to get the software all back on and configured! :-D
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
-
Gary Wheeler wrote:
Everyone has their own workflow that's best for them.
Very true. It's a fine balance, I think: I don't like a checked in version that won't run, or throws continual NotImplementedExceptions, and I try to avoid thinking of version control as a backup system! :laugh: Instead I have my NAS and automatic incremental backups that I don't even see, much less think about. I can understand both you and your team member's position: he doesn't want to issue code that he isn't sure is final in case it gets used and has to become final by default. But you want it backed up so weeks can't be lost... Perhaps a "proper" backup system for your PCs to work alongside the SVN/GIT route would be useful? I know damn well I wouldn't want to have to rebuild my current PC without good backups - it would take me days to get the software all back on and configured! :-D
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
We do have a backup system available; it requires some individual initiative to use it. Some do, some don't. Based on prior experience, our herd of cats doesn't work well with an automated backup mechanism.
OriginalGriff wrote:
SVN/GIT
If only. We're still using SourceSafe, believe it or not. One of my 'spare time' projects (yeah, right) is to get our source control moved to something else this year. Current candidates are MS Team Foundation and SourceGear Vault. My uninformed impression is that Git wouldn't work for us, based on its apparent complexity.
Software Zen:
delete this;
-
So, I'm doing some analysis code, and I need a couple of moving averages - one over the whole sample, one over the last 30 samples, and one over the last ten samples. Now, I don't fancy doing that in SQL, so I'm doing it in C#, and I decide the obvious thing to do is create a MovingAverage class that you Add samples to, and it sorts itself out. Easy peasy. So I knock up the class framework, and the code that will use it, and then go back to fill in the class. And decide to make it generic because hey, I might want to use it again. Change everything to use generics - easy - and off we go...except...you can't sum generics, because they are based on
object
which doesn't implement arithmetic operators. And you can't restrict generics to classes that support arithmetic either... So either I restrict it to just primitive types (int, double, blah blah blah) or I drop the whole idea...and you can't use primitive types as generic constraints...and it wouldn't work if you could, because primitive arithmetic is implemented viastatic
inline functions at compile time, so you couldn't use 'em in a generic if you wanted to! So...change it back Griff, change it all back... :doh:Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
There a issue on Connect to add IArithmetic interface to the value types, but it seems to be going nowhere. https://connect.microsoft.com/VisualStudio/feedback/details/94264/arithmetic-types-like-int-double-decimal-should-implement-iarithmetic-t (NOTE: for some reason, going to that link gives an error -- Other issues are displaying OK)
Truth, James
-
So, I'm doing some analysis code, and I need a couple of moving averages - one over the whole sample, one over the last 30 samples, and one over the last ten samples. Now, I don't fancy doing that in SQL, so I'm doing it in C#, and I decide the obvious thing to do is create a MovingAverage class that you Add samples to, and it sorts itself out. Easy peasy. So I knock up the class framework, and the code that will use it, and then go back to fill in the class. And decide to make it generic because hey, I might want to use it again. Change everything to use generics - easy - and off we go...except...you can't sum generics, because they are based on
object
which doesn't implement arithmetic operators. And you can't restrict generics to classes that support arithmetic either... So either I restrict it to just primitive types (int, double, blah blah blah) or I drop the whole idea...and you can't use primitive types as generic constraints...and it wouldn't work if you could, because primitive arithmetic is implemented viastatic
inline functions at compile time, so you couldn't use 'em in a generic if you wanted to! So...change it back Griff, change it all back... :doh:Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
You can use the
System.Linq.Expressions
namespace to create generic operators quite easily. For example, see Marc Gravell's Generic Operators[^] from the MiscUtil library[^].public static class GenericOperator<T>
{
private static Func<T, T, TResult> CreateCore<TResult>(Func<Expression, Expression, BinaryExpression> body)
{
try
{
Type typeT = typeof(T);
var left = Expression.Parameter(typeT, "left");
var right = Expression.Parameter(typeT, "right");if (typeT.IsEnum) { Type enumType = Enum.GetUnderlyingType(typeT); var x = Expression.Convert(left, enumType); var y = Expression.Convert(right, enumType); Expression op = body(x, y); if (op.Type == enumType) op = Expression.Convert(op, typeT); return Expression.Lambda<Func<T, T, TResult>>(op, left, right).Compile(); } return Expression.Lambda<Func<T, T, TResult>>(body(left, right), left, right).Compile(); } catch (InvalidOperationException ex) { string message = ex.Message; return delegate { throw new InvalidOperationException(message); }; } catch (ArgumentException ex) { string message = ex.Message; return delegate { throw new InvalidOperationException(message); }; } } private static Lazy<Func<T, T, TResult>> Create<TResult>(Func<Expression, Expression, BinaryExpression> body) { return new Lazy<Func<T, T, TResult>>(() => CreateCore<TResult>(body), true); } private static readonly Lazy<Func<T, T, T>> \_add = Create<T>(Expression.Add); public static Func<T, T, T> Add { get { return \_add.Value; } } ...
}
"These people looked deep within my
-
So, I'm doing some analysis code, and I need a couple of moving averages - one over the whole sample, one over the last 30 samples, and one over the last ten samples. Now, I don't fancy doing that in SQL, so I'm doing it in C#, and I decide the obvious thing to do is create a MovingAverage class that you Add samples to, and it sorts itself out. Easy peasy. So I knock up the class framework, and the code that will use it, and then go back to fill in the class. And decide to make it generic because hey, I might want to use it again. Change everything to use generics - easy - and off we go...except...you can't sum generics, because they are based on
object
which doesn't implement arithmetic operators. And you can't restrict generics to classes that support arithmetic either... So either I restrict it to just primitive types (int, double, blah blah blah) or I drop the whole idea...and you can't use primitive types as generic constraints...and it wouldn't work if you could, because primitive arithmetic is implemented viastatic
inline functions at compile time, so you couldn't use 'em in a generic if you wanted to! So...change it back Griff, change it all back... :doh:Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
Overloaded operators? Can we do those? In C#? :doh:
-
Gary Wheeler wrote:
Everyone has their own workflow that's best for them.
Very true. It's a fine balance, I think: I don't like a checked in version that won't run, or throws continual NotImplementedExceptions, and I try to avoid thinking of version control as a backup system! :laugh: Instead I have my NAS and automatic incremental backups that I don't even see, much less think about. I can understand both you and your team member's position: he doesn't want to issue code that he isn't sure is final in case it gets used and has to become final by default. But you want it backed up so weeks can't be lost... Perhaps a "proper" backup system for your PCs to work alongside the SVN/GIT route would be useful? I know damn well I wouldn't want to have to rebuild my current PC without good backups - it would take me days to get the software all back on and configured! :-D
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
Rebuild PC? Oh. Right. Mine's a company XP machine. The fun should all kick off in about a month.:~
-
Overloaded operators? Can we do those? In C#? :doh:
Yep! But not in generics...the generic parameter (as far as the compiler is concerned) derives directly from
object
unless it is constrained so you can't use methods other than those that apply toobject
. And you can't constrain to basic types...There's an interesting interview covering this here: http://www.artima.com/intv/generics.html[^]Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
-
Rebuild PC? Oh. Right. Mine's a company XP machine. The fun should all kick off in about a month.:~
I meant when the HDD goes south, as it will one day. But upgrade the PC / OS and you get a long job as well...:~
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
-
So, I'm doing some analysis code, and I need a couple of moving averages - one over the whole sample, one over the last 30 samples, and one over the last ten samples. Now, I don't fancy doing that in SQL, so I'm doing it in C#, and I decide the obvious thing to do is create a MovingAverage class that you Add samples to, and it sorts itself out. Easy peasy. So I knock up the class framework, and the code that will use it, and then go back to fill in the class. And decide to make it generic because hey, I might want to use it again. Change everything to use generics - easy - and off we go...except...you can't sum generics, because they are based on
object
which doesn't implement arithmetic operators. And you can't restrict generics to classes that support arithmetic either... So either I restrict it to just primitive types (int, double, blah blah blah) or I drop the whole idea...and you can't use primitive types as generic constraints...and it wouldn't work if you could, because primitive arithmetic is implemented viastatic
inline functions at compile time, so you couldn't use 'em in a generic if you wanted to! So...change it back Griff, change it all back... :doh:Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
You know, sometimes going backwards it's the only way to go forward. ;P
CEO at: - Rafaga Systems - Para Facturas - Modern Components for the moment...
-
So, I'm doing some analysis code, and I need a couple of moving averages - one over the whole sample, one over the last 30 samples, and one over the last ten samples. Now, I don't fancy doing that in SQL, so I'm doing it in C#, and I decide the obvious thing to do is create a MovingAverage class that you Add samples to, and it sorts itself out. Easy peasy. So I knock up the class framework, and the code that will use it, and then go back to fill in the class. And decide to make it generic because hey, I might want to use it again. Change everything to use generics - easy - and off we go...except...you can't sum generics, because they are based on
object
which doesn't implement arithmetic operators. And you can't restrict generics to classes that support arithmetic either... So either I restrict it to just primitive types (int, double, blah blah blah) or I drop the whole idea...and you can't use primitive types as generic constraints...and it wouldn't work if you could, because primitive arithmetic is implemented viastatic
inline functions at compile time, so you couldn't use 'em in a generic if you wanted to! So...change it back Griff, change it all back... :doh:Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
I had exactly the same issue a few years ago when I built a ring buffer class to calculate a moving average. Indeed, it would be nice to be able to have something like an INumeric interface or a way to filter generics which can support arithmetic! In the end I just used
double
s, which was more than OK for my specific needs and allowed me to use the same class withint
s and such. :)In theory, there is no difference between theory and practice, but not in practice. - Anonymous A computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match. - B. Bryson