You all know what STL is (ok, not all of you, some have skipped C++ altogether and some have only created a few Carnivore/Herbivore classes for Uni).
But you don't know what STT is.
Well I'll tell you, just sit nicely and listen.
STT is "Silly Tip & Trick".
This is one:
You probably already know of the collection initialiser syntax introduced into C# 3.0:
At times, you'd have a long list of items in the initialiser, and you find yourself doing copy&pastes to add lines, or removing lines from the list. There's this little extra step you need to do, that is making sure that you have a comma between any two adjacent lines.
That makes the copy&paste a bit annoying.
However, it appear that csc.exe would accept an extra trailing comma at the end of the list, so this code is 100% valid:
Now it's easier to text-manipulate the list.
It also works for Enum declarations:
So, even though having three cats in the house is busy enough, as far as c# is concerned I can easily add more of these. Not sure what the existing cats would think of that.
Just to make sure it actually works:
curiosities:
Here in Israel, there's a reality/documentary TV show called "The Sharks".
It's about people who have some kind of a business idea, and are looking for investors.
Each entrepreneur gets a few minutes to present their idea and business plan in front of 4-5 well-known Israeli businessmen, trying to get their support in return for percentages of their project.
One can differentiate the totally bad projects with possibly OK projects, simply on the basis of a proper preparations. Some projects are simply vague ideas that popped up on someone's head, without any business plan of any kind.
Then you have the projects that comes with a detailed business plan, market research, pricing policies and what-not. These are of course the ones that the Sharks (potential investors) show interest in. The interesting bit is that most of the times, instead of asking strictly business related questions, they tend give more importance to the actual usability of the proposed product/service/whatever. They try to get in the head of the potential consumers and look for Achilles' heels from the user's point of view.
The point is, that you cannot create a product or service to solve problems that you think that people have. You have to solve actual problems that potential consumers are facing.
Paraphrasing DHH from a presentation lately, "It's not Rocket Surgery". You should simply solve people's problems, otherwise they won't be interested.
Who is the better consumer than yourself?
Example: There's this person I know, who will sell you baby carriers. They look very simple in first glance, but then you see that it's actually pretty useful - it's adjustable, you can re-use the same carrier in several carrying positions (low, high, front, back), and it's comfortable for parent and baby. The thing is - she didn't wake up one day with a crazy idea, hoping it'd match someone's needs. She made one for herself and her baby, making it better with time, and then thought - 'hey someone else might like it'
Going back to DHH and his presentation, he states there clearly that the whole RubyOnRails thing was simply something he needed for his day job, so it became very useful, as the consumer (himself) was giving him direct feedback during the development process.
Same can be said on many OSS projects, like NHibernate, the whole Castle stack and many more.
I can testify on AspView, which I created to make my day job easier and more fun, as I disliked WebForms and my employer insisted on ASP.NET and C# all around - that was my best shot. I got immediate feedbacks from the consumer (myself and my team members) so it stayed focused on solving consumer needs.
You should be trustworthy. I evangelise the use of good tools, and I name the Castle stack, NHibernate, Rhino Commons, and more as good tools. I can do this whole heartedly since I use these very tools for my day jobs, on paid projects, not only for pet projects.
Take ASP.NET MVC. This project is being internally run by a team of developers, who their day job is to build this tool, not to use it. On the surface it presents a major problem, no consumer feedback.
The way they chose to solve this problem was pretty simple. Expose as much as you can to the public. Push potential users to play with the API, experiment with use cases, build extensions, whatnot. Continuously grab community input, incorporate it in the product, and get new feedback. All that has started from the earliest stages by ScottGu, then Phil Haack. The while team seam to be everywhere, from mailing lists to ALT.NET conferences, getting consumer input and building around it.
The outcome is that they can focus on solving consumer problems, and the progress of improvements is amazing. It got to the point that I have no problem at all with using ASP.NET MVC, even though I'm an active member in MonoRail. Personally I prefer MonoRail, but I really see ASP.NET MVC as a viable option, and recommend it as a possible solution.
Take the Entity Framework. I've been hearing about this beast from 2005. However being able to get the feel of it took way too long. Meanwhile it appear that a lot of stuff has been introduced into it, that might not even be interesting to consumers, while rendering fixing the consumers' problems more difficult.
And as for trusting your own tools - I've heard once that Visual Source Safe was never used internally for development within Microsoft. I also don't really believe that there is a single public major website under Microsoft's umbrella that uses SqlDataSource, heavily customised GridView components and other widely demo-ed Webforms stuff.
Technologies like Silverlight, ASP.NET MVC, not to mention the more experimental stuff like IronXYZ and F#, find their way into community review, and even to internal production use. Microsoft are voting confidence in these products, so do I.
So as far for the notorious Vote of No Confidence in EF, I never have joined it as it simply make no sense imo. It simply does not interest me enough to even vote. They way I see it, EF belongs next to WebForms, while MVC/IronXYZ/F#/etc are legitimate ALT.NET
Cuz ALT.NET is not about opposing anyone. Definitely not MS - hey these guys brought us the CLR and BCL.
It's also not about being the freedom guerilla fighters fighting the evil Corporate. Not at all.
I think that ALT.NET is a great idea, just like XP (Extreeme Programming), and like XP it has a bad name, as it implies 'niche', 'alternative', 'scary', 'elitist', 'vane'.
It's not.
It's about good tools, built to help make us developers work better, and have more fun during. Parts of the DevDiv are as ALT.NET as it gets.
In SQL Server, you have two main types of Indexes, one that allow duplications, and one that does not.
However, if you want a rule like "I want to forbid duplications, except for null values" you do not have a built in feature for that, as the unique index will treat the NULL value as a real value, thus allowing up to a single row with that NULL.
Apart from refactoring the DB schema, the solution I usually was doing has been to create a trigger to deal with that:
CREATE TRIGGER dbo.People_Unique_NonNull_Email
ON dbo.People
AFTER INSERT
AS
BEGIN
SET NOCOUNT ON
DECLARE @Count INT
SELECT @Count=COUNT(p.Id)
FROM People p
JOIN INSERTED i On i.Email = p.Email
WHERE i.Email IS NOT NULL
IF @Count > 0
BEGIN
RAISERROR ('Cannot put a duplicate email on People table', 16, 1)
ROLLBACK TRANSACTION
END
END
GO
However, Moran Benisty, my T-SQL Ninja pal, has pointed out that the SELECT and IF might bit a wee bit apart, and revised this to
CREATE TRIGGER dbo.People_Unique_NonNull_Email
ON dbo.People
AFTER INSERT
AS
BEGIN
SET NOCOUNT ON
IF EXISTS(SELECT 1
FROM People p
JOIN INSERTED i On i.Email = p.Email
WHERE i.Email IS NOT NULL
)
BEGIN
RAISERROR ('Cannot put a duplicate email on People table', 16, 1)
ROLLBACK TRANSACTION
END
END
GO
I'll leave adding the UPDATE case to the readers
I've refined my "unit testing framework" a bit, to make it less awkward.
the code:
test(Fact/Test):-
current_predicate_under_test(Predicate),
retractall(test_def(Predicate/Fact/Test)),
assert(test_def(Predicate/Fact/Test)).
setup_tests(Predicate) :-
retractall(test_def(Predicate/_/_)),
assert(current_predicate_under_test(Predicate)).
end_setup_tests:-
retractall(current_predicate_under_test(_)).
run_tests :-
dynamic(tests_stats/2),
bagof(P/Tests, bagof((Fact/Test), test_def(P/Fact/Test), Tests), TestsPerPredicate),
run_tests(TestsPerPredicate, Passed/Failed),
write_tests_summary(Passed/Failed).
run_tests(TestsTestsPerPredicate, TotalPassed/TotalFailed) :-
run_tests(TestsTestsPerPredicate, 0/0, TotalPassed/TotalFailed).
run_tests([], Passed/Failed, Passed/Failed):-!.
run_tests([P/Tests|Rest], Passed/Failed, TotalPassed/TotalFailed):-
write('testing '), write(P),
foreach_test(Tests, PassedInPredicate/FailedInPredicate),
write(' passed:'), write(PassedInPredicate),
(FailedInPredicate > 0, write(' failed:'), write(FailedInPredicate) ; true),
nl,
Passed1 is Passed + PassedInPredicate,
Failed1 is Failed + FailedInPredicate,
run_tests(Rest, Passed1/Failed1, TotalPassed/TotalFailed).
foreach_test(Tests, Passed/Failed):-
foreach_test(Tests, 0/0, Passed/Failed).
foreach_test([], Passed/Failed, Passed/Failed):-!.
foreach_test([Fact/Test|Rest], Passed/Failed, NewPassed/NewFailed):-
assert((run_test:-Test)),
(
run_test, !,
NextPassed is Passed + 1,
NextFailed is Failed
;
NextFailed is Failed + 1,
NextPassed is Passed,
write('FAIL: '), write(Fact), nl
),
retract((run_test:-Test)),
foreach_test(Rest, NextPassed/NextFailed, NewPassed/NewFailed).
write_tests_summary(Passed/0) :- !,
nl,
write(Passed), write(' tests passed :)'),
nl.
write_tests_summary(Passed/Failed) :-
nl,
write(Passed), write(' tests passed, however'), nl,
write(Failed), write(' tests failed :('),
nl.
reset_all_tests:-
retractall(test_def(_/_/_)).
the usage:
:- setup_tests('conc/3').
:- test('empty and empty returns empty'/(
conc([], [], [])
)).
:- test('empty and nonempty returns L2'/(
conc([], [1,2], [1,2])
)).
:- test('nonempty and empty returns L1'/(
conc([1,2], [], [1,2])
)).
:- test('nonempty and nonempty returns L1 concatenated with L2'/(
conc([1,2], [3,4], [1,2,3,4])
)).
:- end_setup_tests.
my current test output:
| ?- run_tests.
testing conc/3 passed:4
testing create_list/3 passed:2
testing empty_pit/5 passed:1
testing get_opposite_pit/2 passed:2
testing in_range/2 passed:2
testing is_in_range/2 passed:4
testing put_seeds/5 passed:3
18 tests passed :)
yes
I've been looking at getting a new laptop lately.
Currently my options are:
Dell Latitude 830 (15")
Dell XPS 15"
Sony Vaio CR (14.1")
I'll probably go for a 8300/7500 cpu.
Centrino 2 rigs on Sony site are only for 13" and 16", and I've seen none on Dell's site
My main concern is with the clarity of the screen.
I am very happy with my Toshiba screen (Tecra A3 15", matt, 1024X768). I don't like the new trends of high resolution (tiny fonts) and glossy screens (I want to see my code, not my face. I'm too damn pretty - it's distracting).
Any input is welcome
Well, not *that* slow apparently.
The lesson:
Don't be afraid of powerful tools.
You can use reflection right, gain the power, while not losing too much performance.
Quoting from nhusers mailing list:
How much you be scare about the use of reflection in NH if 1.000.000 of access to get & set to a field mean 0.2seconds ?
--
Fabio Maulo
Finally I'm sitting down to be done with my Computer Science degree. I've been studying in the Israeli Open University starting 2003, while working full time and more. Over than two years ago I reached the point of having literally no time at all to finish it up, so I left it to be with only two final projects to complete, present and defend.
The first one is to write a simple AI enabled game (using depth delimited alpha-beta algorithm variation) , in PROLOG.
Back when I took that course, the whole paradigm was too strange to me. I've been doing procedural and OO coding for years, and the look of the programs just looked .... wrong.
Nowadays that I developed a lot of curiosity into declarative languages like Erlang and F#, (and being a much better and way more experienced developer) I can relate to that type of coding more easily.
So, dusting the rust of two year of not touching it at all, I sat down today to start working on that project (delivery is next month), I started with writing down a small helper for running unit tests on my code.
Ain't pretty, but it serves both the need to test my code, and the need to re-learn the language:
run_tests :-
dynamic([
tests_passed/1,
failing_tests/1,
total_tests_passed/1,
total_failing_tests/1 ]),
assert(tests_passed(0)),
assert(failing_tests([])),
assert(total_tests_passed(0)),
assert(total_failing_tests([])),
bagof(
(Module/Predicate, Tests),
tests(Module/Predicate, Tests),
TestDefinitions),
run_tests_definitions(TestDefinitions),
retract(total_tests_passed(TotalPassedAtEnd)),
retract(total_failing_tests(TotalFailedAtEnd)),
len(TotalFailedAtEnd, TotalFailedAtEndCount),
write('summary:'), nl,
write('Passed: '), write(TotalPassedAtEnd),
write(' Failed: '), write(TotalFailedAtEndCount), nl, nl,
(TotalFailedAtEndCount> 0, write_fails(TotalFailedAtEnd) ; write('Alles Gut'), nl).
run_tests_definitions([]) :- !.
run_tests_definitions([(Module/Predicate, Tests)|T]) :-
write('module: '), write(Module),
write(' predicate: '), write(Predicate),
write(' ... '),
run_tests(Tests),
retract(tests_passed(Passed)),
retract(failing_tests(Failed)),
assert(tests_passed(0)),
assert(failing_tests([])),
len(Failed, FailedCount),
write('Passed: '), write(Passed),
write(' Failed: '), write(FailedCount), nl,
retract(total_tests_passed(TotalPassed)),
retract(total_failing_tests(TotalFailed)),
NewTotalPassed is TotalPassed + Passed,
conc(Failed, TotalFailed, NewTotalFailed),
assert(total_tests_passed(NewTotalPassed)),
assert(total_failing_tests(NewTotalFailed)),
run_tests_definitions(T).
write_fails([]) :- !.
write_fails([H|T]) :-
write_fails(T),
write(H), write(' failed'), nl.
run_tests([]) :- !.
run_tests([H|T]) :-
run_test(H),
run_tests(T).
run_test(Test) :-
call(Test),!,
tests_passed(X),
retract(tests_passed(X)),
NewX is X + 1,
assert(tests_passed(NewX)).
run_test(Test) :-
failing_tests(X),
retract(failing_tests(X)),
NewX = [Test|X],
assert(failing_tests(NewX)).
% Asserts
assert_all_members_equal_to([], _).
assert_all_members_equal_to([H|T], H) :-
assert_all_members_equal_to(T, H).
this code is allowing me to define my tests like the following:
tests(moves/change_list, [
change_list__add_first__works,
change_list__add_middle__works,
change_list__add_last__works,
change_list__empty_first__works,
change_list__add_middle__works,
change_list__add_last__works
]).
change_list__add_first__works :-
L = [1,1,1],
change_list(L, L1, 1, add),
L1 = [2,1,1].
change_list__add_middle__works :-
L = [1,1,1],
change_list(L, L1, 2, add),
L1 = [1,2,1].
...
invoking the tests is as simple as the predicate:
:- run_tests.
and the current output from my project is:
module: utils predicate: in_range ... Passed: 4 Failed: 0
module: utils predicate: create_list ... Passed: 2 Failed: 0
module: moves predicate: change_list ... Passed: 6 Failed: 0
module: moves predicate: move ... Passed: 1 Failed: 0
module: moves predicate: step ... Passed: 1 Failed: 1
summary:
Passed: 14 Failed: 1
step__when_ends_within_same_player_pits__works failed
yes
Ahm. A failing test .... back to work I guess.
btw, The game I am implementing is Kalah.
Following Ayende's post on Patch management approaches using centralized SCM, here are how I would have dealt with the 4 issues that he brings up, using a Decentralised SCM.
I use git, so I'll use git terms here. I guess it's quite similar for other DSCM systems.
Note that I haven't used patches on git development as until now all of my git work was on repositories I had write access to, However the principals are the same (i.e. - all of the tree is local to my machine, thus I can reach any point in the history locally).
First I'll clone the hosted repository to my local machine.
So, using a DSCM, I can work locally with the benefits of a SCM, have as many branches/features as I want. the whole tree is stored locally, and its blazing fast to switch branches, so I can easily work on every aspect I want, and easily create a patch from every node in the history tree, to send to the project owners.
Some more AspView love:
This dude, Morten Lyhr (great blog - go on and subscribe), has taken the sample MonoRail Getting Started project and AspView-ed it.
can you guess why this makes me happy?
This is the output of building Castle's trunk, both for .NET 3.5 and .NET 2.0, after inserting AspView into the core project. Took me a while as I had to:
So, soon enough (hopefully by the end of this day) you'd be able to see AspView on the build server.
Thx again for all of the users and patch-contributors for your faith in this library.
Following many other good fellas, (like Scott Hanselman, Damien Guard, Phil Haack, Justin Angel and many more), one more has joined Microsoft.
Hamilton Verissimo, the founder of Castle Project, and an inspiration to myself and many others, would most probably serve as another great power in the DevDiv, which appear to be an awesome place to work at, more and more every day.
Way to go Hammett.
A cute programming languages quiz.
It'd show you 12 snippets of code, and you'd have to guess the programming language the code is written in.
If you have only started coding in the late 90's then you're in trouble.
heck, even if you have started on late 80's. I mean, really.
As I've been exposed to programming from a very early age, on the first half of the 80's, and my father being and old time punching-cards hacker, and I also tend to reach for the new stuff these days, I managed to score a nice rounded 12/12 100 points.
Can you?
It's on "First in first served" basis, and there is a limited capacity, so go ahead and register at the conference page:
You'd need an openid identity in order to register. If you don't have one, that's be a great opportunity to get yourself one. it's free, and it's gaining more and more popularity as a SSO mechanism for the web. I'm using myopenid.com - signing up was simple, easy and fast.
IMPORTANT:
Please do not register, just because of the free admission if you don't think that you'd come. Otherwise you'd be taking a place of someone else's.
If you do register and later on find out that you won't be able to take part, please contact us organisers so we'd be able to add people from the waiting list.
if you blog - go ahead and spread the word.
if you can - tag it with "alt-net-israel" and/or "altnetconf" so it would propagate to the aggregators.
cya there
I'm really pleased to announce that there is going to be an Alt.Net conference in Israel, namely Alt.Net.Israel.
If you haven't heard of Alt.Net yet, read David Laribee's post to better understand the term - What's ALT.NET
The conference will be held on Thursday 7th and Friday 8st August 2008, at the SQLink offices in Ramat Gan, and is being organised by Roy Osherove, Oren Eini (a.k.a Ayende), and myself.
Thursday 7th, at 18:30-20:30: planning meeting, following a walk to a nearby pub or coffee shop to socialise.
Friday 8th, at 09:30-16:30: sessions.
We have chosen a summer Friday and a super accessible location on purpose, to give the religious people a chance to attend and still make it on time home for Sabbath.
That is really up to the people who attend. We will be following an open spaces format, similar to the other alt.net conferences in the UK, USA and Canada, where the agenda is decided by the conference participants. Anyone can lead sessions on particular topics of interest, participate as an attendee or just hang around and chat with interesting people.
Please note that registration is not open yet! I will blog more when we have information on this, hopefully it will open shortly. I can say that the conference will be free of charge.
If you have any questions, please feel free to contact us. I'm really looking forward to this, should be a great event!
See you there :)
P.S, also a big thankyou to Ben Hall, of the alt.net UK organisers, which is partly responsible for my enthusiasm for alt.net conferences, and I've also used his previous announcement as a template for this one ...
Serving as a mental note, and as a service to dear readers who hadn't been bitten by this yet.
javascript's parseInt method is not the same as .NET's int.Parse.
there's this 'radix' argument which is meant to tell the parseInt method whether we want to treat the string we parse as binary, octal, decimal, hexadecimal or whatever.
Now the naive programmer (a.k.a. myself) would think that the default is always base 10, so parseInt(x) === parseInt(x, 10) for every x.
Apparently parseInt tries to outsmart us, and it's actually guessing the radix if not set. so if x begins with 0x, it would guess hexadecimal, and if x begins with 0 it would guess it's octal.
so, parseInt('010') === parseInt('010', 8) === 8
ok, I can live with that maybe.
however it would also 'guess' that 09 is octal (even though 9 is not an octal digit !) thus parseInt('09') === 0
I found this by chance, when a Date.parse method I have was parsing "09/07/2008" into a date-info object with day==0, causing it to fall back into today's date
So, the lessons we've learned today:
So after moving to Vista last week, I've tried a full castle build with tests.
Things I had to take care for it to run properly (from easy to not-as):
Now that I have a way to run the build and make sure all tests pass, I can start working on my next Castle assignment - bringing AspView into the core project, but that's a whole other post so keep your RSS reader open ...
My poor old laptop has had a lot of problems lately, priming at ignoring any network connection yesterday and having many problems with svn and git sessions when the network was on, so I decided to re-install.
'twas 1am, so I thought 'what the heck - let's try this vista thing at last'.
It was surprisingly a smooth experience. The initial setup identified almost all of the drivers, but the sound-card and the SD card reader. However, the auto updates (which took over an hour cuz there was apparently a lot to update) took care of the sound, and I got the SD driver from Texas Instrument's site.
What I had to install to make the machine workable for day-to-day work:
still missing (no time) but essential:
btw, since I've installed VS2008 without going 2005 first and without the full SDKs, I ran into a problem with NAnt 0.86b1 - complaining about missing .NET 2.0 stuff. It appear to be a known bug in NAnt, that has been fixed back on late 2007, so I've just switched to a nightly build of 0.86b2 and the problem did go away. I need to make sure that it won't affect my Castle build.
Didn't have much to say here. I consider it a test post (see if Writer will work from Vista) but it beats the crap out of "TEST POST PLEASE IGNORE" ...