Sunday, December 02, 2007

Is GOTO always evil?

The other day I decided to use a "goto" statement in my C# code. It was a difficult decision to take, and was primarily motivated by the need for readability.

Apparently, Linus Torvalds also thinks there are cases where "goto" is appropriate, so I'm in good company...

Thanks to Scott Hanselman for pointing to this thread.

How do you Exactly Approximate??

Let me quote from MSDN about System.Double:

"A mathematical or comparison operation that uses a floating-point number might not yield the same result if a decimal number is used because the floating-point number might not exactly approximate the decimal number."

I found this funny, go figure...

Thursday, November 15, 2007

How consistent should a blogger be?

I recently got back to reading Jeff Atwood's blog, after a long pause on my part. I was very surprised to see advertisements there, especially since I remembered him discussing this issue in the past - opting for the negative. Of course, one can always change his mind. But still, I find it quite funny. Reading the last few comments on that post you can read him agreeing that advertising on a blog is "like advertising on your business card".

Apparently he now doesn't mind advertising on his business card ...

By the way - I found Jon Galloway's comment hilarious...

Tuesday, November 13, 2007

VB Grrrrrr...

Yet another MSDN and .NET WTF:

I'm currently implementing some temporary code that was written in VB into our C# infrastructure (let's skip the details). Anyway, there are parts in the VB code that I would like to group because either they are currently not being used, or for some reason I want to hide it from view and get to it at some later phase.

Obviously, a #Region directive seems like the best solution.

My VB is quite rusted, but using common sense I tried using  the same syntax I'm used in C#. But alas - it didn't work. So I searched MSDN - hey, it should work! Well, VB have this little difference that the identifier_string MUST exist and it must be surrounded by quotation marks. OK, no biggy, I usually put it there anyway.

But why doesn't it work?

Well, there is this tiny little limitation, hidden from you if you rely solely on MSDN, that "'#Region' and '#End Region' statements are not valid within method bodies."

Which raises two questions:

1. Why, in Heaven's name, should there be such a difference between C# and VB. It's just a freaking compilation directive!

2. Assuming there is some justified reason for that (which I doubt - I guess it's just a non-implemented feature) - would it hurt someone to put this info in MSDN so I won't have to get crazy trying to figure out why it doesn't work?!?!

And now to a personal to-remember note:

I relied solely on Intellisense and Resharper to know the code is wrong. I'm using the C# only version of Resharper, so I have no idea whether Resharper would have been more helpful. Anyway - had I compiled from the beginning (or at least looked at the message Intellisense gave me) - I would have seen much sooner why it doesn't work...

Monday, November 12, 2007

Could the World become a Better Place?

Shai Agassi is a person who doesn't have to prove himself - he's done it 400,000,000 ($) times and much more. I had the chance of working for him at TopTier, though at the time he was mostly in the US and I don't think he'll remember me.

He's now investing all his power in the Project Better Place, with the goal of transforming our fuel-based cars into electric-cars, by providing the necessary infrastructure and business plan.

Will he succeed? I sincerely hope so. I am also willing to be one of his first customers for a pilot plan in Israel. If anyone is to succeed in such a project - it's him.

Some say his real goal is to own the software that will handle the whole system. Well, I think that if he succeeds in this project, it makes complete sense and there's no harm about it. If making this world a Better Place means Agassi will own the most important software in history - so be it!

In any case, I admire him for being ready to risk his most valuable asset - his reputation - for this huge and very risky project.

If you want to keep track of what's going on, I suggest you read his blog.

Good luck Shai!

Citations of the day

By Henry Kissinger:

  • Military men are just dumb stupid animals to be used as pawns in foreign policy.
  • If everybody is your enemy, then you are not paranoid.
  • Power is the ultimate aphrodisiac.
  • Corrupt politicians make the other ten percent look bad.

Source: Wikipedia

Sunday, November 11, 2007

XP Printing issues - Grrrr...!!!

D., my colleague came to me today asking for help with printing problems. At some point I decided to log off, but then I couldn't log on again. The machine kept saying that the current time is different than the network time. I couldn't log on with any of our domain users (including Administrator), so I had to log on with the local Admin user. Looking at the time, it looked fine. After digging and searching for 15 minutes, we discovered that the date differed - running some simulation D. had to move his clock one day ahead and forgot to move it back.

Once we moved the clock back to the right day, he could print flawlessly!

Things gives rise to many questions:

1. Why couldn't he print when his day was wrong? I understand there are synchronization issues involved - but in 2007 (almost 2008) these things shouldn't happen! Sometimes you really can not have all your computers synchronized. That's life!

2. Why did the error talk about time and not date?

3. Why couldn't we even log on with a domain user?

Grrrrrrrrrrrr........!@#!@#!@#@!@#!@#!@#

Wednesday, November 07, 2007

Supermarket 2.0

A paraphrase of Web 2.0 to real life - GREAT!

Monday, November 05, 2007

Parameterized SELECT TOP

Just a small tip:

Say you want to run a query that returns the first @X results of some query, such that @X is a parameter.

The simple "SELECT TOP @X ..." statement doesn't work. I found this weird, because I know for a fact that SQL 2005 supports using a parameter in the TOP clause (as opposed to SQL 2000 where you had to use either dynamic queries or the SET ROWCOUNT statement).

Solution - surround the parameter with parenthesis as so:

"SELECT TOP (@X) ..."

Something to remember...

Monday, October 29, 2007

We're Hiring - Searching for a Quantitative Analyst

For the past few years I've been working for a global investment firm. At the beginning I worked part-time as a freelancer, but recently the company opened an R&D facility in Herzliya and now I'm a full time employee again. We're now looking for exceptionally talented quantitative analysts, to participate in the development, validation & documentation of risk & analytical applications and processes.

Our firm has been engaged for over 10 years in the research and development of systematic trading models for the global financial markets. The developed models are used in the actual money management of clients' portfolios.

Role will involve working on new risk management models, data extrapolation, and trading model analysis and development.

Requirements:

· MS or PhD in Math or Physics

· Exposure to stochastic calculus

· Excellent general modeling skills

· Grasp of PDE’s and Monte Carlo

· Experience in statistical data analysis or signal processing is a plus

· Experience in Matlab \ C# is a plus

· Financial knowledge is a plus

To apply, fax your resume and a cover letter to 09-970-7329 or email careers@eaglets.com

Grrrr... I hate bad documentation! or: "An INSERT EXEC statement cannot be nested"

I recently had to extensively use a feature in SQL I seldom used before - inserting the results of an EXEC statement directly into a table. Sounds a reasonable thing to do, right? Accidentally, I had a bunch of stored procedures calling each other, using temporary tables, and finally filling a "final" table. I finished writing the whole thing, and then - BABOOM! - it doesn't work, because "An INSERT EXEC statement cannot be nested". Huh? What?
Why? Why didn't you say so before?

Following is a quote from SQL Server Books Online for "INSERT (Transact-SQL)" :

execute_statement

Is any valid EXECUTE statement that returns data with SELECT or READTEXT statements. The SELECT statement cannot contain a CTE.

If execute_statement is used with INSERT, each result set must be compatible with the columns in the table or in column_list.

execute_statement can be used to execute stored procedures on the same server or a remote server. The procedure in the remote server is executed, and the result sets are returned to the local server and loaded into the table in the local server.

If execute_statement returns data with the READTEXT statement, each READTEXT statement can return a maximum of 1 MB (1024 KB) of data. execute_statement can also be used with extended procedures. execute_statement inserts the data returned by the main thread of the extended procedure; however, output from threads other than the main thread are not inserted.

Did you see any clear mention of this limitation???

Thursday, October 25, 2007

SQL Table Variables - Limitations

I've come to really like table variables in SQL. They are a nice and natural development of database programming. And, when used smartly, can greatly improve performance compared to using temporary tables.

Today I've discovered that table variables cannot be truncated. I had no idea...

Anyway, I've found a cool source of more information about table variables, including some stuff that is not or not well documented in Books Online. Check here and here.

When you think of it - it makes sense. As far as I know, table variables are memory constructs whereas temporary tables are kept in tempdb. Truncating a table simply removes the reference of the table's page from the database. However, if the table is only kept in memory and in no actual database - it has no meaning...

Wednesday, October 24, 2007

I type at 48.1 wpm and 97.2% accuracy

I took the typing test everyone talks about, here are the results:

Number of words typed: 144
Test duration: 3 min
Speed: 48.1 words/min. (240 keystrokes/min.)
Error penalty: 4
Accuracy: 97.2%

It's good, but I've got a lot to improve. I must say it made me quite nervous - causing me to make several time-consuming errors (didn't get high accuracy for nothing). Also for me, writing code goes way faster (even before counting Intellisense, Resharper and the like in) than text I've never seen before. There are some words, or parts of words that I can just type at lightning speed (new, class, for, if, the, select, from, ...)

Confession

Scott Hanselman, THE blogger, has a very interesting post about The Five Second Rule. Actually, the comments are the most interesting...

I was born in Belgium, moved to Israel at 13 and have been living here ever since (almost 20 years). I've never heard of this rule.

I must, however, confess that when I was a little child I would scratch chewing gums off the ground and eat them with no second thought. I did this until one day my sister Tali saw me, utterly shocked, and gave me an important lesson in hygiene...

Tuesday, October 16, 2007

I miss my const methods

Yet another thing to add to the list of things I miss in C# - the ability to define a method in a class that is guaranteed (by the compiler!) to not change the state of the object (like const methods in C++).

I don't understand the implementation of System.Double

Take a close look at the implementation of System.Double (use Reflector or any other dissassembler).

Look, for example, at the following excerpt:

public const double PositiveInfinity = (double)1.0 / (double)0.0;
public const double NaN = (double)1.0 / (double)0.0;

 


Huh?!?! What ?!!? Why ?!?!


Of course, I had to run and check:

double myNaN = double.NaN;
bool isInf = (double.IsPositiveInfinity(myNaN));
// isInf is set to FALSE

double myInf = double.PositiveInfinity;
bool isNaN = (double.IsNaN(myInf));
// isNaN is set to FALSE

 


It doesn't end there. Look at the implementation of IsNaN:

public static bool IsNaN(double d)
{
return (d != d);
}

 


All'n'all, I must confess I can't make any sense of all this!


I promise to publish if/when I do.

Google - what are you cooking

[UPDATE: Apparently I was a little bit late at noticing. See here for a news article on the subject dated October 15th.]

Only a week ago, my GMail account had an allocation of less than 3GB. Two days ago it crossed the 3GB line, and now it's almost 3.5GB.

Call me crazy, but I think there is something behind this. Is Google about to (at last!) remove the "Beta" label from this great product? Are they about to take over some big data storage firm?

What's up big G ? You're up to something, I know it...

Why Double.IsNaN

If you have a double value set to NaN you can check that it's NaN only through the Double.IsNaN method. MSDN quote: "Use IsNaN to determine whether a value is not a number. It is not possible to determine whether a value is not a number by comparing it to another value equal to NaN."

In other words, there is no guarantee that (Double.NaN == Double.NaN).

A simple question - WHY ?

Sunday, October 14, 2007

Wine is better than Water

I just got this in my mailbox. I rarely read, let alone forward, this kind of mails. Yet, it came from a person I trust and who avoids sending stupidities (thanks Yuval!) and I really feel I ought to pay it forward...

"

As Ben Franklin said:
In wine there is wisdom, in beer there is freedom,
in water there is bacteria.


In a number of carefully controlled trials,
scientists have demonstrated that if we drink 1 liter
of water each day, at the end of the year we would
have absorbed more than 1 kilo of Escherichia coli,
(E. coli) - bacteria found in feces. In other words,
we are consuming 1 kilo of poop.


However, we do NOT run that risk when drinking wine
& beer (or tequila, rum, whiskey or other liquor)
because alcohol has to go through a purification
process of boiling, filtering and/or fermenting.

Remember: Water = Poop, Wine = Health

Therefore, it's better to drink wine and talk
stupid, than to drink water and be full of shit.

There is no need to thank me for this valuable
information: I'm doing it as a public service.

"

Defining a Startup company

First, I would like to draw your attention to this post (and blog in general): 

Defining a Startup company « First steps in the Hi-Tech sales world .

It's maintained by a guy (I think) who writes anonymously about his experience in the Hi-Tech world. I usually don't fancy anonymous writers, but this is the exception that confirms the rule - by being anonymous he allows himself to be free of any politically-correct barriers, and not being afraid of being sacked by writing what he thinks about his work and employer. The result is well-written, interesting, thoughtful, funny, and still written with style and manners. Give it a try, you'll like it!

Anyway, I'd like to asses the issue of defining a Startup company. Inevitably, I had to check what Wikipedia had to say. The emphasis there is more on the company's age ("limited operating history"), size and potential growth. In general, they are more concerned with the financial aspect of the matter - a Startup company is a company that is highly scalable and can produce huge ROI very fast. They also mention that it usually focuses on creating a product, rather than providing services.

In The Beginner's other post and comments, people related more to the atmosphere at work:

Not Startup (anymore):

"When you have a purchase order system in place that is automated and requires the signatures of half the company (company size is irrelevant here) for a purchase of a paper clip."

"Feeling like a small bolt in a large machine where you can no longer influence anything"

"people covering their asses by adding the whole company on every email they send"

"working your ass for some idiot that has a reserved parking space that is never occupied before 9:30 am or after 5:30 pm, who is earning 5 times your pay and who’s only donation to the company is when he keeps his mouth shut and doesn’t generate any trouble by releasing another stupid decision"

 

Still Startup:

"A small place, good atmosphere, people working all to one goal."

"the added bonuses - a pool table, cool offices, or some other crap"

 

IMHO, there is no single definition to a Startup company. I've seen companies of 15 that could never be considered a Startup, and worked together with almost 150 other employees for a superb Startup. In every company you have smart people, and those who are smarter, you have "the company ass-hole", and after you've worked for a place enough time - some things start bugging you badly, Startup or not.

So where should the line be drawn?

Well, I think that there are many parameters involved. No Startup fits all of these parameters, and some of the parameters are purposely vague, but in general, a company who complies to most of these parameters, is likely to be, to some degree, a Startup company. Almost sounds like a Fuzzy Logic rule...

So here is my (incomplete) list, in no particular order:

  1. Size - a Startup company must be small. At least it should feel small to the employees as well as to the outside world. I've worked for a company with almost 150 employees who still felt small, but that's rather uncommon, and very difficult to achieve.
  2. Age - the company and employees must feel young. It doesn't mean you can't have workers of 50+. If you even have one, young, important and charismatic individual - it could do the job. I've also seen companies where people of 30+ were called "the eldest", and still the company felt old. So don't go firing all your guru's with 20 years of experience now!
  3. Speed - in a Startup company, things move fast. Decisions are taken on the spot. The word "process" is only used as a running instance of a computer program! The overall mood can switch from one extremity to the other in a few minutes. People walk fast in the corridors. There is action in the air!
  4. Belonging -  people feel they belong to something great. There is a purpose to your work. When someone asks you something, you help him because you want him to succeed, knowing it will help us. You'll delve into his problem until completion, even if you'll have to solve it yourself.
  5. Believing - employees must know and believe in the company's goals and capability to reach these goals. They must also feel that they are making a difference - they must believe in their ability to impact the company's success.
  6. Potential - it should be evident that, in all matters (company size, sales, products, ...) - there is much more to be done than that which has been done. There should be a feeling of huge potential. Also, employees should have the feeling that once part of this potential will be achieved, they will be significantly compensated financially (stock options, bonuses, etc.).

(Note: I feel I haven't finished this post - I'll complete this list later on...)