#Google Analytic Tracker

Pages

Dec 1, 2010

In LINQ, is Take(n) really the same as Select Top n?

Today I was doing some bug fixes and I ended up wanting to do something like “Select top n From ..” in Linq.  I realized that there isn’t really a Top keyword. Ideally I would like something like this:

var result = from i in itemList
where SomeCheck(i)
select top 10 of i;

Of course,there is no TOP in LINQ. I asked my colleague what should I do, she said use Take(n). It’s true, Take(n) returns you n number of item from an IEnumerable. For example, you can do something like

var result = (from i in itemList
where SomeCheck(i)
orderby i.Rank
select i).Take(10);

However in my case, it is a bit more complicated then that. This method SomeCheck() maintains a state. Doing the above would call this method based on the count of itemList.  What I really want is I want to stop calling this SomeCheck method once I get 10 items.

Take() != Top()

Now then you think about now Top works in SQL Server, I would have guess that a query such as “ Select Top 10 * From [someTable] Where [SomeSlowEvaulation] ” would only evaluates “SomeSlowEvaulation” up to the point we get all 10 items. This cannot be achieve by using Take(n).

My Solution to My Own Problem

To achieve what I want, I ended with something like this:

var count = 0;
var result = from i in itemList
where count <= 10
where SomeCheck(i)
where count++ > -1
select i;

You may wonder what the heck am I doing. What the above code does is that it stop evaluate SomeCheck(i) once I get 10 or less items in the result. The code is very straight forward. Once count <= 10 failed, LINQ stop evaluating the rest of the where statement. If SomeCheck(i) passes, then it has to run count ++ > –1.  In the above case, you can join all these statements together, but it is easier to read the code in this format.

So, why would I want to do that. Of course there is a business logic why I can’t call SomeCheck(i). This method does two things, it checks if I want the result, and it caches the data at the same time. You can see that the flaw in this method is that it does two things at the same times. However, back then it appears to be a good idea.

The only one thing that the above solution can’t minic the top is that it doesn’t stop evaluating until it finished the list. In SQL, if you select top 10 out of 10 million records, you would expect SQL Server does not loop though the entire list.  In my case unfortunately it still does.

Conclusion

If you Google Top for Linq, you will find that most of the answer are using Take(). In most cases it Take() will work. However, just like anything, just because there is an answer to a problem you search, it doesn’t it is the right solution for you. You should always dig a bit deeper to the problem to ensure the answer applies to your problem.

Jun 24, 2010

.NET Remoting Causes Security Exception After Upgrade to .NET 4.0

This may well be my last blog post on .NET Remoting. I am not sure how many applications out there still using .NET Remoting, but the current trend is to migrate from .NET Remoting to WCF. Eventually, we will, but in the meantime, the product I am working on will still relay on .NET Remoting.

Yesterday, I updated all the VS project target framework from .NET 3.5 to .NET 4.0.  Usually migrating from one version of .NET framework to a newer one should be fairly simple.  There are some difference between .NET 3.5 to .NET 4.0, for example MS removed the CAS and promote the use of Security Transparent Code. It also introduces new classes like Tuple, which is useful for represent data from a data row.

After changing all the target frameworks and rebuild the solution, everything should works just like before. Started my server and client app, boom…. System.TypeInitializationException!!!

Exception

Exception: "The type initializer for 'ME.APTS.ServiceInterface.DataAccess.DataAccessBase`1' threw an exception."

Inner Exception: System.Security.SecurityException {"Request failed."}

Stack Trace:

 
Server stack trace: 
at System.Runtime.Serialization.FormatterServices.nativeGetSafeUninitializedObject(RuntimeType type)
at System.Runtime.Serialization.FormatterServices.GetSafeUninitializedObject(Type type)
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ParseObject(ParseRecord pr)
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Parse(ParseRecord pr)
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record)
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryHeaderEnum binaryHeaderEnum)
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Remoting.Channels.CoreChannel.DeserializeBinaryRequestMessage(String objectUri, Stream inputStream, Boolean bStrictBinding, TypeFilterLevel securityLevel)
at System.Runtime.Remoting.Channels.BinaryServerFormatterSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders, Stream& responseStream)
 
Exception rethrown at [0]: 
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at ME.APTS.ServiceInterface.IBroadcastListener.Process(ArrayList broadcastQueueArrayList)
at ME.APTS.Service.Provider.Remoting.BroadcastQueueRemoting.Process(ArrayList listOfObjectsToProcess) in C:\dev\Streets\Main\APTS\ME.APTS.Service.Provider\Remoting\BroadcastQueueRemoting.cs:line 119

This exception is being throw by my client app, when my server app tries to do a remoting call on the client application. The server when to send a piece of data to the client, and it needs to create an object, but apparently the server has no permission (that’s what I assumed) to create object on the client side.

The Confusion

After spending hours debugging the problem, it became even more confusing when some client application works and some aren’t. These client applications run the same piece of code on the same machine, and yet only some of them work.

Trying to confuse myself more, I tried to look for security attributes setting that we may have used. Nothing turns up. Since we didn’t change anything in the code and not even the application configuration files, it must be changes in the .NET framework.

Debugging

After hours of frustration, my brain was too tired to think. I asked my colleague to look into this issue together. After a couple of testing,  we realized we forget to check the client configuration file. We don’t use App.config, but our setting file is in a very similar format. After doing some configuration files comparison, BINGO!

Solution

It all comes down to a missing .NET Remoting setting, which is highlighted below.

<configuration>
  <system.runtime.remoting>
    <customErrors mode="off" />
    <debug loadTypes="true" />
    <application >
      <service>
        <wellknown mode="SingleCall" objectUri="BroadcastListener.rem" type="ME.APTS.Client.Model.BroadcastListener, ME.APTS.Client.Model" />
      </service>
      <channels>
        <channel ref="tcp" port="9999">
          <serverProviders>
            <formatter ref="binary" typeFilterLevel="Full" />
            <provider type="MyCompany.SecurityServerChannelSinkProvider, MyCompany.ServiceInterface" securityPackage="NTLM" impersonationLevel="impersonate" authenticationLevel="call" logging="true"/>
          </serverProviders>
        </channel>
      </channels>
    </application>
  </system.runtime.remoting>
  <appSettings>

After specifying the typeFilterLevel attribute to Full, the app works again. Here is the strange part, why all of the other working application has a specified typeFilterLevel, and not the one that I was debugging. I checked the existing release build, which runs on .NET 3.5, and it doesn’t have this setting either.

Conclusion

The only conclusion I can draw from this is that a change in .NET 4.0 causing this issue. By default, the typeFilterLevel is set to low. The application that I was testing must have been using the low setting. From the typeFilterLevel documentation, it isn’t clear when you should use typeFilterLevel.Low or typeFilterLevel.Full.

Low: The low deserialization level for .NET Framework remoting. It supports types associated with basic remoting functionality.

Full: The full deserialization level for .NET Framework remoting. It supports all types that remoting supports in all situations.

The changes in .NET Remoting security cause my application to use typeFilterLevel to full. It maybe related to the changes of the CAS. It would be interesting to see what exactly has changed, but there is no time for it. Soon our application will migrate to WCF and .NET Remoting will become the past.

May 28, 2010

My 1st Code Rush Experience – Can I Code Without ReSharper?

I have been a big fan of ReSharper (R#). I started using R# probably about four years ago.  Back then, this tool was magical to me, I didn’t know why MS VS wouldn’t have R# features.

C# 4.0 and Visual Studio 10 are already out.  I notice Code Rush (CR) is gaining popularity.  I tried CR probably about 3 years ago, but I felt CR wasn’t the right tool for me, especially I was heavily relaying on R# code analysis refactoring features. CR may had some code analysis and refactoring tool back then, but I can’t seem to remember much.

About a couple month ago, one of my colleagues came back from the MIX10 and he was impressed by Devexpress demo. He actually got one free license for CR + Refactor Pro. Since I was not in MIX10, I can’t say much about the demo. From words I heard, some guy code a lot faster when using CR while another guy still haven’t finish playing his guitar.  My colleague would like me to try out CR + Refactor Pro.

I was still using R# 4.5, and 5.0 is out. It is about time to see if I should upgrade to 5.0, or try a new tool.  My development team has finished the development phrase, and has moved into the QA phrase. Ideally in this period, we no longer code any new functionalities, other than testing and fixing issues. I think this would be a good time to try a new code aiding tool like CR.

Btw, we try to be as agile as possible. We tested new features in each iteration.  However, our QA team still have to do many regression tests because we don’t have enough automation tests. The QA team is very good at finding issue where developers didn’t thought about. As a result we still have a QA phrase.

What I Want to Talk About

Please assure that I am NOT suggesting either one of the tools (CR or R#) is better than the other. I believe CR and R# have their strong and weakness.  What I like to talk about is my experience of switching from R# to CR.

Why Trying CR

As I said before, I have been a big fan of ReSharper. However, using ReSharper comes in a price.  Here are the issues that I have using R#

  • Averagely I has to restart VS once a day due to OutOfMemoryException
  • R# slows down VS when it tries to analysis large classes

Basically these are the only issues I have with R#. Please don’t get me wrong here, R# is an awesome tool. However it needs a lot of resources to do the code analysis so that you don’t have to keep recompiling to discover your mistake. Unless you are a programming god, who make no mistaking in coding, otherwise you would find R# save you time from recompiling.

I was actually hoping that CR + Refactor Pro would somewhat provide me similar features that I use in R#, and it would also speed up my Visual Studio.

About 3 years ago, my development team were using VS 2005 coding with C# 2.0.  I tried to convince my team member to use R#.  The result… I failed miserably.  R# was very slow. Even now I still try to get my team to use R#, but they refused to use it because they worry it will destabilize VS. This is the same for CR.

Also, I won’t dare to install both CR and C# together. It would be nice to have the best from both products.  However, the last thing I want is a messed up IDE with shortcut key clashing. 

Installing Code Rush

The first time I downloaded the DXperience Product installer, I was confused at first of what I needed to download. I want to download CR with Refactor Pro, but instead, I downloaded the DXperience Product installer, which actually includes all the DX product. I think this is a very nice integrated products installation setup.

Before I start installing, I shut down VS, just like installing R#. Unfortunately the first thing I saw is the following:

1

Not sure why it complains why MS Visual Studio .NET is still running. I checked the Task Manager and found nothing running that may be related to VS (devenv.exe).  I wasn’t too impress. So I had to  log out and log in into Windows. That seems to fixed the issue.

During the installation, I like how it takes ask for your experience level. I saw a number of posts complaining R# has too much dialogue boxes when performing refactoring. I think R# should have a similar feature, that allow beginner to learn the tool though dialogue boxes, and no dialogue boxes display for expert users.

 2

First Thing I See in CR

Great, the installation was successful, let see how this work. What is this red line on the left of my code?

3At first, I wasn’t too sure the meaning of this, but soon I realized it means there are errors in the code. It was confusing because I can’t understand why the entire piece of code are errors.  My solution compiles. I wasn’t too impress about seeing the red line.

In the above example, It is nice that it point out the “issue”, but I don’t really understand what it means by “Complex member”. I think it needs to have a link for me to learn more about what it means.

Incorrect Analysis?

I started getting more confused because CR can’t seem to analysis the solution I was working with.  For example, why would Data.EmployeeName is an Undeclared element in the following screenshot? One possible reason I guess is that CR failed to analysis this data class. This class is a code generated ADO dataset definition. The generated definition is huge, more than 100,000 line of code, I think. From a design perspective, I want to get rid of this class and try other technology like the Entity Framework, but it is too hard to get rid of legacy code!

Anyways, I was disappointed that CR not able to analysis this class properly, but I understand if CR need to analysis this class, it will slow down VS. However, seeing the error indicators on your code while there isn’t any errors really bugs me. That makes the analysis useless because I can’t really tell what is working and what isn’t working. I would rather not see any code analysis.

Btw, R# usually takes about 3 minutes to analysis this data class (if I accidentally navigated to class designer file). So, better remember to add exception file to R# option so that it won’t do code analysis.  Also, if I keep the designer file open for too long, I may run into OutofMemoryException. However, the bottom line is that R# has no problem of analysis the designer code or code that uses the class.

4

Another thing that I didn’t like to see is the following “Member is not implemented” warning. It is true that I didn’t implement anything in this method. However, I have to implement this because the class implemented an interface that requires the following method. I wonder if there an option I can mute this warning.

9 - Cant check the interface

Undisposed Variable Detection

CR can detect if I remember to dispose a IDisposable object. I think R# should have this feature. Good job to CR.

5 - Disposable check

No Linq or Extension Method Supports

It starts hurting my eyes when CR keeps giving me incorrect analysis. Linq and extension method is out for quiet some time, so I was disappointed of not seeing the correct analysis.

11 - Linq not supported

Testing Tools

One of the most use features in R# is the testing tool.  I can’t live without an integrated testing tool in a test-driven development.  With R# 4.5, it even supports native NUnit framework, which I greatly embraced.  In the older version, some of my NUnit doesn’t work because I was using new NUnit feature that R# doesn’t support. With R#, I don’t even need to install TestDriven.

I was also hoping CR would have something similar. Unfortunately I wasn’t too impress when some of the working tests failed to run correctly. Also, why CR would have the “Run test(s)” option when I right click on a private method. The code wasn’t even in a test suite. That’s confusing.

6 - Incorrect Test detection

Alt + F12 Reference Search

Another set of features that I used a lot in R# is search and navigation tool. I know that CR may not be as powerful as R#. When I tried to use the normal Alt + F12 reference search feature, CR failed to find reference call by interface.  Maybe there is an option to turn on search by interface, but I couldn’t find one.

Also, the CR search result does not look appearing with my IDE color schema (screenshot bolow). Maybe that’s why R# would rather has its own search result tab, instead of integrating the IDE color schema in the search result.

7 - busy screen and find all reference is werid

I have to admit that I am so used R# navigation and search tools that I will have to find an exact replace before I can give up on R#. Being an expert user in one tool makes it a lot harder to switch to another tool.

One thing that I find annoying is CR can’t find interface reference call. In R# it can do searches on both search using interface or concert reference call.

Learning from Shortcuts

So, one way to learn how to use a new tool is from reading it shortcut. Like R#, so I printed out an CR shortcuts reference and sticks it on my wall. Of course the list of shortcuts can only help me so much, so I tried to discover new feature from the option menu. Whoa…

8 - complicated screen

I didn’t realized you can customize how your shortcut key can execute. You can decide how an shortcut work if your cursor is at the beginning of a word, in the middle, after and many more.

I am guessing this is for the advance users. You can customize the way that you want your IDE to work. However, I have to debate that is this feature best for the users. I think having this many options can be overwhelming, and it is too powerful. It may cause key clashing with other VS shortcuts. If you didn’t backup your sophisticated shortcut settings and lose it, you can get very upset.

Refactoring

One of the big selling feature of CR + Refactor Pro is that it has many refactoring tools you can use.  From what I heard, you can do a lot more refactoring using CR then R#. However, since I only do C# development, I can’t see much benefit for me, like refactoring HTML.

Another thing I find that weird is the following: Can you consider “line-up parameters” refactoring? I would have considered this is a matter of code formatting. I use R# code reformatting tool a lot.

10 - Formatting vs Refactoring

CR also has code clean extension. One thing I heard a lot from CR fan is the power of the DXperience extension framework.  It has a strong community and it provides many free extension. However, I haven’t realized this power during my CR experience.

Conclusion

So, for the CR fans who happen to be reading this post, you may notice that I have been complain CR and rarely talk about CR advantage.  In the beginning of this post I have mentioned that I am not here to say which product is better or not. I merely want to share my experience. 

I believe CR has many good features for developers. At from what I read online, if you can master CR, you can be a very fast coder. 

For me, I don’t need to be a faster coder, but I do good code analysis tool. R# code analysis, search and navigations feature helps me a lot. In the end, you need to pick the right tool that suit your need.

It may also be a bad time for me to try CR since I was in the QA phrase. It may have been better if I use CR for new development, then I may see more benefits in CR. I have only tried CR for 3 days. So I can’t really do feature by feature comparisons.

The only reason that I was considering switching from the beginning was because of R# performance.  The good news is that these frequent OutOfMemoryException that I got from R# has NOT been crashing the entire VS since version 4.5. I can live with it. Resharper exception can be reported back to JetBrains. That’s pretty cool.

image

As a result, I stick with R# for now.

May 26, 2010

Who are the Business Analysts (Part 3/3)

What did I learn?

In summary, I learn a lot of who are the BA, and their roles in the business world. However, merely attended a two days conference do not make me a BA.  It has given me more ideas if I want to move from a technical orientated career to a business orientated career. Another important thing I learned is that there are many hybrid BAs, existing in between the non-technical and the technical worlds. I find that more people move from technical to more a business role than the other way around.

Do Company Needs BAs?

During the conference, I kept wondering why do company need a BA. The answer is very simple. If a company wants a dedicated person to do business analysis, it hires one.  Typically in a small company, resources are tight, and the employees usually have multiple roles. Most likely there wouldn’t be a single person doing business analysis. As the company grows, employees who are interested in business may move to a more business orientated rule , like project manager. If the company keeps growing, sooner or later it will have dedicated people to do just the business analysis.

Do I want to be a BA?

So, after knowing more about the BA, I asked myself do I want to be a BA, or be interested in moving to the business.  In the current stage of my career, BA is probably not what I am looking for.  Not pointing finger at anyone, people who treat software development as a job rather than a career would tell me they want to get into more a business-orientated such as project manager, product manager, business analysis and etc.  The argument lays on the assumption that non-technical position is more interesting than dry technical position.  A number of engineering friends decided to study MBA or business courses in order to move to a business orientated career.  Unfortunately I rarely hear people moving from a non-technical position to a technical position. Possibly it is easier to do a non-technical job. Possibly it is more fun to attend business meetings, travel to other places, talk to real people, instead of sitting in a office typing your life away.

To me, as long as software development is fun and enjoyable, I will keep doing it.  However, I know that some time I may no longer able to keep up with the changes in the technical world, may eventually move to a less technical position.

Who are the Business Analysts (Part 2/3)

In the conference, there are quite a number of presentations I could choose to go. Here were the ones that I attended:

  1. Collecting, Connecting and Correcting the Dots – Roger Burlton, BPTrends
  2. From Tactical to Strategic: A Business Analysts Path to Leadership – Kathleen Barret, IIBA
  3. Experience Agile: The Lego Game – Kim Szuta & Chris Lavallee, ThoughtWorks Canada
  4. That’s what I said but not what I meant or … Getting the Language right, right from the start – Gale Anshelm, Sierra Systems
  5. Panel – Metrics – What and how do you meansure a BA’s work? How do you know what makes a good BA?
    Moderator: Aman Sidhu, Cenovus Energy,
    Panellists: Marlene Barker, MLB2 Enterprise Ltd
    Andrea Borle, CGI
    Murray Laatsch, Enerplus
  6. Agile Requirements: Critical Success Factors for Acceptance Test Driven Development – Jennitta Andrea, The Andrea Group, Inc.
  7. Requirements Gathering for Business Intelligence and Data Warehousing Projects - Francisco Rios Gascon, RIOSOFT LTD

By all means all these topic are interesting. However, I find that materials presented were general a guideline instead of a “How to”, or “Best Practice”. That is probably the biggest different when compare a technical seminar with a non-technical seminar. Every businesses deal with their own problems. There is no single recipe that would solve the business problems. As a result, a guideline would be more appropriate.  

How to Measure a BA Success

As mentioned before in my last post, one of the most interesting topics is how to measure a BA success. A BA may involve in many aspects of a business. Some BAs have direct influences to the business case, some are indirect.  These aspects may not be quantifiable. For example, if a BA implements new policy that improve the moral inside a company, what metrics do you use to determine how successful the BA did his/her job? If a BA proposes a new features development for a piece of software, which indirectly drives the sale of the hardware , could you easily relate the sale increase of the hardware is due to the BA decision.

In the world, we tries to come up with “thing” to be measure.  Some suggests I heard were: compare the BA with a benchmark, BABOK, PM inputs, objective counts, etc.

Just like everything, we create an abstract of things we want to measure. For me, this is just human nature. In the conference, one of the presenter talks about her company would invest money to figure out how to measure their BA performance.  Unfortunately I found that most of the discussion focused too much on tools and methodologies on how to measure a BA, but not so much on how to improve the BA.

If you step back and think about the reason you hire a BA , the basic reason comes down to the fact that you want to make your business more profitable.  I hope that companies would focus on improving the BA skills, and performance, instead of emphasising the measuring part.

Agile and ATDD

ATDD – Acceptance Test Driven Development

As a software developer, I probably heard this term “Agile” at least one or twice a week. Just last week my team watched an agile development video.

There are many favour of agile software developments. My team is moving from the tradition waterfall software development to SCRUM development. I can probably spend months and months to talk about agile, but that isn’t necessary since you can easily google it.

In the conference, one of the topics presented is acceptance test driven development. Regrettably, I have to express my disappointment in the content that was presented. The content focused too much on “how to write a acceptance test”, instead of “how ATDD improve your software development” or “how to apply ATDD to your software development”.

Instead of presenting what I learned about how to write an acceptance test, I would like to talk about how ATDD is integrated in an agile development. Remember, ATDD is NOT a requirement in agile development, instead, agile development promotes the use of ATDD.

In agile development, it is very important to have fast feedback, and deploy results. With ATDD, it helps to ensure new development does not break old functionalities, and ensure new functionality works. The test is one of the important feedbacks for the development team, or the BA to know the health or your software product.  As your software becomes more complex, more tests will be needed. As a result, your tests need to be maintainable. Many time the tests need to be refactored because the business requirement changes.

Your tests ensure the quality of your software, but you also need to ensure the quality of the tests. Here are some tips:

You want the acceptance tests to be:

  1. Based on business cases – when there is a business requirement, there should be an acceptance test.
  2. Readable – BA needs to understand what the tests do, and Developer needs to read the code easily
  3. Easily to maintain – Business cases changes all the time, the tests need to be easily refactored, or be prepared to toss the tests and write a new one
  4. Useful – Don’t waste time on writing tests that cover the same thing over and over again. Testing scenarios that never happen is useless too.
  5. Can be automated – i.e. Continuous Integration, which is another big topic that can’t be covered here.

Ultimately, you want to test your software as much as possible to ensure it works.

Data Warehousing

Another interesting topic that I attended was about data warehousing.  I won’t get into the detail of what is data warehousing. However, there are two points that I like to share. When you want to develop a data warehouse, please remind yourself these:

  1. You need a business case to create a data warehouse
  2. Use waterfall model, no agile!

The presenter pointed out that data warehouse extracts very specific information from the database. If there is no business case to create, you shouldn’t spend invest resources in creating one.  Developing a data warehousing can be expensive, and you want to do it right in the beginning. It is hard to modify afterward. That also lead to the 2nd point, use waterfall model when developing a data warehouse.  Data warehouse tends to be rigid, changes are very hard to make once it is created. Therefore the waterfall development model works best.

Who are the Business Analysts (Part 1/3)

About a month ago I was given an opportunity to attend the BA World conference in Calgary.  BA, which stands for business analyst, describes those professional who analyze the business. This was a two days conference, and the ticket was around $800 CND. This is rather an expensive conference relatives to my past conferences.

So, why did I paid to attend this conference which has almost nothing to do with programming? Well, I didn’t pay. I was lucky to win a draw for a free ticket in one of the CAMUG (Calgary Agile Methodology User Group) seminars. I would like to thank CAMUG organized the monthly seminar, and gave out free tickets to the conference.

Welcome to the BA World

I had never attending a non technical conference, so this is a totally new experience for me. The majority of my time deals with technical matters.  I kept reminding myself to stay away from being too technical when talking to the people in this conference.

I particularly remembered two things from the keynote that seems to be a recurring challenges for the BA in this two days conferences:

  1. BA has not been receiving the recognition that he/she should have deserved.
  2. BA as a discipline is not well defined, and the BAs need to promote themselves better in the business world.

These two problems puzzled me in the beginning.  However, soon I understood the reason behind it as the conference progresses.

Here are my reasons:
First, BA is relatively a new discipline, and yet people in the business world has been practicing BA. It just that it was not well defined the role of a BA in a company. In another, BA is a very general term describes people who analysis business.  Second, it appears that many company’s employees act somewhat like BA.  In another sense, there is not a need for a specific BA role if everyone in the company does a bit of BA so that company can archive its goal.

As a result, to better define BA as a profession, an organization called IIBA was created.

Role of a BA

In general,  BAs help the company grows.  For example, they do this by providing specific objectives for the company to achieve.  They might help implements polices, business processes to ensure the company stays in focus.

Specifically, BA may do some of the followings:

  • Collect business requirements
  • Linking the people to come to a business solution
  • Implement a new business process or policy
  • Finding new business opportunities
  • Finding opportunites to save company money

Values of a BA

The following diagram shows the values of a BA in an organization

image 

Types of BA

Generalist – This is basically the standard BA. This person oversees the general aspect of a business. A example would be a management consultant.

Specialist – This person has focus on a specific aspect in a business. For example: Data Analyst, Methodology BA, Process Analyst.

Hybrid – This person carries multiple roles in a company. For example, BA/PM, BA/QA, BA/Developer.

My Thoughts

BA as a professional appears to be very general. It almost like if you are doing business, but can’t find a proper title in a company, you will be categorized as a BA.  That’s properly one of the reasons why BA is not that well define.  However, because the profession appears to be very general, it seems hard to measure the performance of a BA.  This has become one of the most interesting questions in the conference – how do I measure the BA performance.

Feb 18, 2010

C# Overriding Base Class Explicit Method

Recently one of my colleagues asked the team how to override a base class method that was declared as explicit. This is actually an interesting question. An there is a lengthy discussion on why you can’t override a explicit base class method from your derived class.

http://bytes.com/topic/c-sharp/answers/271737-how-can-i-call-base-interface-method

The first question is, can you call a base explicit method?

   1: using System;
   2: namespace CSharpCodeTest
   3: {
   4:     interface IFoo { void Foo(); }
   5:  
   6:     class A : IFoo
   7:     {
   8:         void IFoo.Foo()
   9:         {
  10:             Console.WriteLine("A.Foo runs");
  11:         }
  12:     }
  13:  
  14:     class B : A
  15:     {
  16:         public void MyFoo()
  17:         {
  18:             IFoo mySelf = this;
  19:             mySelf.Foo();
  20:         }
  21:     }
  22:  
  23:     class Program
  24:     {
  25:         static void Main(string[] args)
  26:         {
  27:             B b = new B();
  28:             b.MyFoo();
  29:         }
  30:     }
  31:  
  32: }

The compiler works, and I got my result. So, we are able to call our explicit base method through the use of “this”.

So, the next step is try to override B.Foo()

   1: using System;
   2: using NUnit.Framework;
   3:  
   4: namespace CSharpCodeTest
   5: {
   6:     interface IFoo
   7:     {
   8:         void Foo();
   9:     }
  10:  
  11:     class A : IFoo
  12:     {
  13:         void IFoo.Foo()
  14:         {
  15:             Console.WriteLine("A.Foo runs");
  16:         }
  17:     }
  18:  
  19:     class B : A, IFoo
  20:     {
  21:         void IFoo.Foo()
  22:         {
  23:             Console.WriteLine("B.Foo runs");
  24:         }
  25:     }
  26:  
  27:     [TestFixture]
  28:     public class TestCases
  29:     {
  30:         [Test]
  31:         public void Test1()
  32:         {
  33:             B b = new B();
  34:  
  35:             //Call by casting IFoo
  36:             ((IFoo)b).Foo();
  37:  
  38:             //Call by casting A, then by IFoo
  39:             A a = b;
  40:             ((IFoo) a).Foo();
  41:         }
  42:     }
  43:  
  44: }

This is the result

image

So, in this sense, polymorphism still works. That means I am allow to create my own Foo() in the derived class.

How about I try to call base.Foo(), in my override Foo() that is non-explicit?

   1: class A : IFoo
   2: {
   3:     void IFoo.Foo()
   4:     {
   5:         Console.WriteLine("A.Foo runs");
   6:     }
   7: }
   8:  
   9: class B : A
  10: {
  11:     public void Foo()
  12:     {
  13:         IFoo mySelf = this;
  14:         mySelf.Foo();
  15:     }
  16: }
  17:  
  18: class Program
  19: {
  20:     static void Main(string[] args)
  21:     {
  22:         B b = new B();
  23:         b.Foo();
  24:     }
  25: }

Hey, it works too, once I cast the “this” into IFoo, I can still access the base.Foo().

At last, what if I try to override this explicit Foo()? I changed the code from “public void” to “void IFoo.Foo”

   1: class B : A, IFoo
   2: {
   3:     void IFoo.Foo()
   4:     {
   5:         IFoo mySelf = this;
   6:         mySelf.Foo();
   7:     }
   8: }

Ouch, infinite loop. In fact, I have to explicit declare class B with IFoo in order for the compiler to work. Even if I try casting to A:

   1: class B : A, IFoo
   2: {
   3:     void IFoo.Foo()
   4:     {
   5:         //IFoo mySelf = this;
   6:         IFoo myself = (IFoo)(A)this;
   7:         myself.Foo();
   8:     }
   9: }
Nothing will work.
 
The reason is because class B can only have one IFoo implementation. When I explicitly declare B as IFoo, and implemented the IFoo.Foo(), class B no longer has the original class A.Foo().
 
AND… unfortunately there is no special syntax or format to tell the compiler to execute base.IFoo.Foo(), therefore there is no way to call the base.Foo().

I believe this is a missing feature in C#. If C# allows you to call base.Foo() through the IFoo(this).Foo(), you should allow to call it when overriding the method.

To hack around the problem, in the forum, one suggested to use reflection:

InterfaceMapping map = GetType().BaseType.GetInterfaceMap(typeof(IFoo));
map.TargetMethods[0].Invoke(this, new object[]{});

I would suggest try to create a wrapper class if possible, instead of create a derive class.

In fact, there is a FXCop rule on this issue: http://msdn.microsoft.com/en-us/library/ms182153%28VS.80%29.aspx