The last day of Tech-Ed, two more lectures to go: TDD, MVP & UX - (by Ron Jacobs) Ron made a great lecture, about Test-Driven-Development and about having a rich User-interface (or as he called it, not only interface but also experience - with events) but still can test it using Model-View-Presenter pattern. he also explain the differences. Here are some great posts for the differences: Martin Fowler, Alex, Nikola. He also talked about Passive View. and showed a great code sample (I didn't find the presentation or the code in his blog, The sample was great, I wish it will be uploaded to its blog) My grade to Ron's lecture: 9/10 F# Introduction - (by Luke Hogan) Luke had a great lecture about the F#. F# is a functional (and Object Oriented) programming language for .Net, which is something very geeky I might say. (you can found his lecture & samples here). There are some cool things I found useful in this language such as using the let for variable and methods using the same syntax, for example: let data = (1,2,3) let g(x) = sum + x*x the data is immutable by default so it will reduce the frequency of bugs by reducing the amount of special case-code. it is also can be passed between threads easily. Something else in the F# is the pattern matching you can use (I didn't realy know the syntax so it would be better for you reading the code at Luke's blog). you can train yourself with F# using this tutorial. Why using F#? it still not so clear for me, but as Luke said: It is a bridge between the the Dev team and the Research Team. Luke also recommended the usage for the F# for Data-Mining because of the pattern matching, and for scientific data analyst. My Grade to Luke's lecture: 9/10 This is the last post for the TechEd week (here is a link to Day 1, Day2).
Last Thursday a good friend of mine, Shimon Krokhmal, made a great presentation about session hijacking. People asked me: What did he do that make this lecture so special? So I tell you:
- It was well organized from the global idea to prevention.
- I liked the samples - which where recorded prior to the lecture, which let him the ability to show us the best scenarios.
- I learnt few tricks which I didn't know before, this is what I am looking for in a lectures.
Pay him a visit.
At work I have two computers, one with VS2003 (the older one), and on the other one I've installed VS2005, they both share the same user-profile (network profile, I guess).
When building my solution I got this warning: CS1668: Invalid search path 'C:\Program Files\Microsoft Visual Studio\VC98\mfc\lib' specified in 'LIB Environment Variable' -- 'the system cannot find the file specified.' This warning has occurred on each project build.
My first step was to try finding the path, which of course wasn't there. My next step was to search the Environment variables and there it was the LIB variable was pointing on the given path.
As a conclusion, the VS2005 try to load the LIB variables at each build operation, and cannot find it. Just delete the unrecognized paths from the LIB and your VS2005 will stop showing annoying warnings.
Moreover, this is a 1-0 to the VS2005, this is a good example for descriptive error.
* I've heard that this problem happen for others when installing the VS2005 on a computer with VS2003 that has been deleted.
There are things you should hear to understand...
Still hearing the sounds of Tech-Ed, Eliaz Tobias, the one who was in charge of the Architects sessions, publish a post which summarize the ARCast shows that were recorded in Israel 3 months ago.
Those ARCasts recorded In Tech-Ed by Ron Jacobs.
Ron Jacobs is not only a great presenter he is also great interviewer, he knows to ask the right questions at the right time, when you actually think I would like to know ... you can be sure that this question gonna rise out immediately.
Take my advice, get some of those ARCasts to your MP3 Player and listen to this while you are walking, running, taking a bus\train or somewhere else.
For the last period I actually wrote some new infrastructures and upgrade some other older infrastructures. Those infrastructures live in separate solution, and we are using it from our different projects, this infrastructure-solution output (DLLs) are also in use by other programmers from other teams.
In our project-solution we use file reference to those DLLs, using the copy local option, which should cause a copy of the DLLs to the bin directory in the project-solution. This kind of copy should occur every time we build the project and the DLL in the bin directory deferred from the DLL we referenced to (origin path of the DLL).
Most of the time I am working on at least 2 different solution (1 for infrastructures and 1 for my project) and I found out that sometimes after compile my infrastructure-solution and then compile the project-solution the Copy-Local = true does not really copy the file. The result is that you are thinking that you are working on version x.y.z.12 but you are actually working on version x.y.z.11. Believe me it could be very frustrating.
Steps to cause the copy-local to work: 1) Delete the DLLs from the bin directory (project-solution). 2) Build the (project-solution).
I've searched some further details an found this Jelle Druyts's post talking about the same behavior and found the same solution (=none).
Finally, I have my own mediocre solution, while working in solution with file reference that are enable that copy local, add the solution pre-build script for deleting all the files from the bin directory. Any other answer (at least those I've heard) to this problem would be build-time-consumers.
Last week my good friend (and also team-mate :) Doron (aka Control-Master), found strange behavior at the DataGrid Component (.Net 1.1). While playing DataGrid he suddenly see that after postbacks the Grid data disappears (looks like we don't use view state while we actually do). The first thing was the view state of course which looks fine, after a deep dive into his code he found out that he has some code that happens before the Load method which access the DataGrid Items property, causes the DataGrid to lose its Data.
I take this code step ahead while checking this functionality with the .Net 2.0 GridView, which does not have Items property, instead it uses the Rows property. This little difference made me believe that our feature won't reconstruct but I was wrong, this happens again in .Net 2.0.
So, I took deep dive into the .Net components using reflector but couldn't find something useful to tell.
I will keep reading about this, what do you think? is it a bug?
Last month a good friend of mine (Frumi) asked me for help in one of his courses - .Net Project. I explained him everything I could (and thought that would be needed for first project): about how to write a better code, working with delegates, implementing OOP methodology, re-factoring your code etc. When I started to get into the project main idea I asked for a short brief about project requirements.
So, Frumi thought that it would be easier to show me a working example, as he said: "that's how he wanted our project to look like.". I thought, why won't we use here the Reflector? not to copy the project! just to help my friend (and his other friends) to understand this one. So, I show them the Reflector and they like this tool, they even stop asking me questions about .Net.
after a week or two, my friend came to me and ask for help, because he won't be able to submit this work at time and he and his friends tried to copy the code and compile, but it didn't work out.
So, I Google up this one: File Disassembler by Denis Bauer. This is a great Add-in for all of you lazy students, Disassemble everything (files, dlls, methods etc.) into a file.
Installation guide: All you have to do is to download and connect between the DLL and the Reflector (in the reflector menu: View -> Add-ins).
My private opinion: Don't use it for such things, not because it is inappropriate and not fair against the other students, IMHO, you will never be a good programmer if you don't have the passion to write everything on your own, that is the only way to learn new stuff.
History In our application we created a special (user friendly) window for showing messages to the user. The window will get its data, text, buttons through the args parameter.
We will open this window using the messageBox function (this method lies in one of our JS files).
Challenge Everyone knows the annoying default alert of ValidationSummary in ASP.NET. Our messageBox still couldn't rid from the alert that the WebUIValidation.js is popping up on validation error. Why? Because in this JS, Microsoft simply write alert(msg).
Solution Today we wrote those simple lines:
window.alert = function specailAlert(msg) { messageBox("title", msg, button_ok, info_icon); }
This will cause the JS parser to call our function any time the origin window.alert is running. So from now on, when the ValidationSummary will write alert("some useful message"), our method will replace the ugly gray box with our user friendly window.
In one of my code reviews I saw this piece of code (those two methods are in the same class), IMO, and I believe that most of you will agree with me, this usage of exception is unnecessary.
private void CheckPrivileges() { // check user privileges // for authorized user won't do anything.
// if not authorized: throw new UserNotPrivException("user name", "action not allowed"); }
public void DoSomething() { try { CheckPrivileges(); // Continue your logic for authorized users.
} catch (UserNotPrivException) { // showing message box which // says that user has no permissions ShowMessageBox ("User X has no privileges for this place."); } }
Why ?
- The Exception mechanism is slow
- A lot try&catch makes the code harder to read
- Why throw exception if you won't use it? and also throwing it between two methods in the same class?
I would have done it like this:
private bool IsUserPrivileged() { // check user privileges // for authorized user - return true // if not authorized - return false }
public void DoSomething() { if (!IsUserPrivileged()) { // showing message box which // says that user has no permissions ShowMessageBox("User X has no privileges for this place."); return; }
// Continue your logic for authorized users }
If you want to check between those two (privileged or not) you can use the bool. Moreover, when you are not really need the exception data.
Honestly, I wrote this post before Tech-Ed, but didn't have enough time to publish it, in Tech-Ed, I talked with some other programmers that agreed with my opinion, but I still would like to hear your opinion, what do you think about it?
A few days ago I start thinking about a new way to control our web site window size. In our site there is a main window which hold the most important data. For editing the data or view more data: you can choose your subject in the menu and it will open a new page with the full details.
The common sense says that the window should set its own width/height for best fit, with minimum scrolling, but the reality isn't that simple because this page can open either as a regular window or as a modal window and the parameters are different. There is another problem, changing the window size in run-time (in the body) is very ugly (you can see the window re-sizing itself).
The other way is working with JavaScript file which holds the windows parameters and the opener will use this parameters for opening the wanted page. The good thing in this idea is that the menu will know all the sizes and open the windows in the wanted size (the one defined at the JS file). But here we have another problem that Server files (.cs) that writing JavaScript (from server) should know this JS file and the names of the parameters, can cause broken links. also, links to my site that sent via email won't open in the wanted size.
another idea is to use XML for server and at the first time (application) create dynamically the JS file with the parameters, still can cause broken links from (html or other JS) and this can cause a strange problem because we are connecting our files to JS file that is not created yet, I know it will work because it is happening on run-time, but it is still strange. In here we still have the problem for links to my site that sent via mail.
For the mail issue, lets say that every link should go first to my main page, and only their the main window will open the wanted page for you, so we can set the window size via the main window.
I am searching for other implementations to the JavaScript file that holds the sizes for all windows. Is there a better way for doing this?
While reviewing Yossi (new teammate) code I've seen something strange, it looks almost like this:
string formatStr; formatStr = String.Format("Hello {0}",name);
I ask him for explanation and he gave a wonderful story which almost convinces me that this one isn't so bad, it sounds like this:
· This is better than concatenate two immutable strings
· This is more readable.
So I thought for a second and changed the code to look like this:
string concatStr = "Hello " + name;
But he insists that this one is bad, concatenate immutable strings.
So here is my simple explanation:
1. With human-readability I won't argue, it is (sometimes) very individual.
2. My code isn't about concatenating it is about init strings and for that main reason the compiler would change this code to one large string (known at compile time). (You can see the Ildasm).
String.Format implementation remark:
· Be careful, while calling string.Format it creates StringBuilder and do its stuff - do you really want it?
I know that most of you screaming out loud (waaaa.... or just saying: OK and what with 10 or even more concatenation) you probably wrote script generation which look like this:
public string WriteHtmlMessage() { return "<div>" + "I would like to add <b>" + name + "</b>" + "<br/>" + "to my team as a <b>" + job + "</b>" + "</div>"; }
And yes this is an init statement so it is better (performance reasons) writing it like this then using String.Format or even StringBuilder. Even if the compiler will use the Concat method it will be used with the array parameter which is still better than creating String.Builder. Why is it better? Because the size of the array is known at compile time.
Conclusion,
· The compiler will translate the init concatenation to a long string (like my first example) when all the strings are known at compile time (the parameter was const).
· The compiler will use concat method (with arraylist, not the poor pairs concat) when the number of strings are known at compile time (last example).
In both examples this concat is actually faster than StringBuilder or String.Format.
So, next time when you concatenate specific (known) strings do it in the same init instruction.
Last week Avi (my team leader) and I were in a meeting with Systematics the representatives of ESRI in Israel. We ought to ask some questions about the GIS Server, and I will bring here some of the answers we've got:
- The GIS Server 9.1 won't work with the SDE 8.3
- The ADF(Application Development Framework) for .Net will help us to develop GIS applications more productively (using my favorite drag&drop action).
- While the ADF is very useful it is also very simple, most of the wanted features you would have to program by yourself, such as saving the maps history, calculate the distance between two (or more) points which are not in the same extent. (those two examples were implemented in our systems today and won't be provided in the ADF Controls functionality)
- The ADF.Net won't work with the .NET2.0, we should wait for the next release.
- The GIS Server based on the ArcObject model, which give you more functionality (the same as we have in the client) such as editing.
No more activeXConnector problems.
- The performance in the GIS Server is not better than the ArcIms, which are both very slow (you can see it in the examples below)
Here are some demonstrations of the products:
- An example of caching your maps,
I loved the idea of using the cached maps (My Maps) on the right.
- Simple example of tool tips on map (this one is damn slow, while we have only 4 layers).
Those two still suffer from the known issues of bad performance, even when they are only small projects.
Today, while I was sitting with Matan, a new programmer at our team, for a code review - I saw one of the worst practices that each new programmer and even experienced programmers are dealing with during their coding/reading in .Net, the Exception rethrow mechanism.
I would like to show here two code examples for best and worst practices:
After the last Assembly lesson in "What is the difference between Const and Readonly?" post, many of you praised and asked for more from the ildasm subject, so here it is, a simple question about the assembly behind you code.
What going to happen if you'll try to write this code:
public string HtmlSnippet { get { return m_HtmlSnippet; } set { m_HtmlSnippet = value; } }
public string get_HtmlSnippet() { return m_HtmlSnippet; }
This one is simple, This is the error message at the compilation: error CS0111: Class 'Sentence' already defines a member called 'get_HtmlSnippet' with the same parameter types.
Why is it an error? while converting the C# Code into Assembly the compiler will transfer each property into method! after all, there are no properties in assemblies. The format of such transformation will be: public PropertyType get_PropertyName(){....} public void set_PropertyName(string value){....}
Lately I found my self playing a lot with the Google search API, I would like to give my criticism about this one:
Cons:
- Old API as we used to in C (WinAPI) with 8 and even 10 parameters, no overloading.
- Only 10 results for each query, and they rudely ask for the maximum results wanted?!
why isn't there any Const with maximum results so people could be aware of this shortcoming.
- There is no ability to get the page rank.
- In their snippet result (where you can see intro of the text that found for this page) you
will find it in HTML format, which I recognize as poor programming, there are thousands of people who would like to see the results in WinForms, save into file or just read the text, why should I make the formatting job (Isn't it all presentation stuff?)
- Least but not last, documentation for the methods (can be found online only.)
Pros:
- This is a productive tool for all the programmers out there, which can be easily download, install and use this fairly easy.
- Written as WebService which help for compatibility.
conclusion:
- As a programmer who need to search the web, I recommend this tool.
- As a programmer who wrote this tool I would run fast as I could and fix those Cons, and there is even more from the place they came from.
The Cons talk on their own, Does Google made this API poorly to prevent us from using it, or maybe they not as good as they seem to be.
remarks: I hope they won't throw me out from their Ranking Servers :). you can found more data in this article: http://www.mattcutts.com/blog/feedback-products/
There are many people who asking me again and again about this question, I've finally found some time to write about this and show you simple example for all of you out there so you can't forget this.
As we know (read somewhere but nor really remember) one is runtime and the other compile time... so here is the code: public const int IntConstField = 1; public const string StringConstField = "shani"; public static readonly int IntROField = 1; public static readonly string StringROField = "shani";
and this the usage: Console.WriteLine(Class1.IntROField); Console.WriteLine(Class1.StringROField); Console.WriteLine(Class1.IntConstField); Console.WriteLine(Class1.StringConstField);
Isn't It look the same? so I disassemble this one for you...
IL_000a: ldsfld int32 [TestLib]TestLib.Class1::IntROField IL_000f: call void [mscorlib]System.Console::WriteLine(int32) IL_0014: ldsfld string [TestLib]TestLib.Class1::StringROField IL_0019: call void [mscorlib]System.Console::WriteLine(string)
IL_000a: ldc.i4.1 IL_000b: call void [mscorlib]System.Console::WriteLine(int32) IL_0010: ldstr "shani" IL_0015: call void [mscorlib]System.Console::WriteLine(string)
The first four rows show the Readonly, where you can see the ldsfld which is MSIL instruction for pushing the value of a static field into the stack! The other four rows show the Const, Where you can see ldc,ldstr instead of ldsfld which means that Const doesn't behave like Readonly, Const is very similar to to #define in c, don't have its own location as global, Const is just written as number/string (hard coded) at the compile time.
After we know this simple transformation at the compile time, we will see an example including two DLLs:
A: hold the const vars. B: uses A's const vars. When we made a change at A (changing one of the consts) we can't only compile it and replace the DLL at the bin directory, we should also compile this with the DLL who use it (B in our case). So it will change also the hard coded numbers!
PI, is a good const, but Unit Number or Dept Number (=180) isn't good enough.
|