Tuesday, May 19, 2020

Upgrade Angular from 8 to 9 ( follow up)

Well, well, life has never be easy on me, hasn’t it?

After successfully upgraded my Angular 8 project to Angular 9, on the following day, I was so eager to continue on my journey  of Angular quest.

To my surprise, this time, long after clicking on Run button in Visual Studio 2019,  I was presented with this screen:

A screenshot of a social media post

Description automatically generated

I clicked on reload / refresh a few times with no luck.

But if I go to clientApp folder on the command prompt, issue npm start  command, the app works as it should.


After some goggle searching, I found this is the issue seems related to some changes in the way Angular CLI starts up the angular part of the application starting from Angular 9.. click here for the detail description of the issue.

Bottom line, proposed solutions are to set progress. This is true in .Net Core 3.0 as well as .Net Core 3.1. 

There are lots of walk arounds, most of them either does not work or too complex to implement.  After 3-5 attempts, I found a work around I can handle.  Click on here for the original posting   


It only change one line of code in  Startup.cs 

                    //spa.UseAngularCliServer(npmScript: "start");
                    spa.UseProxyToSpaDevelopmentServer("http://localhost:4200");

in place of spa.UseAngularCliServer(npmScript: "start");

replace it with   spa.UseProxyToSpaDevelopmentServer("http://localhost:4200");

where 4200 is the default port of CliServer.

Operational, every time before you want to run the app, you go to ClientApp folder in command prompt issue npm start command to kick off the Angular CliServer, then you click on the run button as you did before,. Here you are the lovely UI presented to your face.

this basically proven that invocation command npmScript: "start" does not pick up the response from Angular CLI Server. The proposed solution call for starting up the CLI Server by manually issuing  npm start command, and let Visual Studio proxy into the CLI Server default port.

 Enjoy Angular and thank you for reading it.

Monday, May 18, 2020

Upgrade Angular from version 8 to version 9

Starting point : a  SPA / Angular project created in Visual Studio 2019 ,


  1. Step 1:  open the project in visual studio 2019 or Visual Code (out of my personal preference, I used Visual Studio Code)., you can confirm the current version by opening package.json file.  Mine was 8.2.12 when I started
  2. Step 2: Step command line in visual studio 2019 or Terminal in Visual Studio Code . make sure you are in /ClientApp directory
  3. Step 3: run this command :  ng update @angular/cli @angular/core  it will run for a long while ( 2-3 minutes I was told, but it took me 10 minutes!). at the end of it, you will see the following message:
    you project has been upgraded to Angular version 9
    for more info, please see http://v9.angular.io/guide/upgrade-to-version -9
  4. Step 4: open up package.json in /ClientApp folder and to verify the new version number . mine is "9.1.7"
  5. Step 5: open main.ts in /clientApp/src folder.  Comment out the following line, ( in my case it is line 22)
    export { renderModule, renderModuleFactory } from '@angular/platform-server'; 
  6. Step 5: open up package.json,  we need to change the following line ( in my case it was line 24) "@nguniversal/module-map-ngfactory-loader": "8.1.1",  To
    "@nguniversal/module-map-ngfactory-loader": "9.0.0-next.9",
  7. Step 6: on the terminal window, run npm install
  8. Step 7 : save all changed files in Visual Studio Code.
  9. Step 8, open up the solution in Visual Studio 2019,  build the solution to ensure, it can be built without error
  10. Step 9: run the program under IIS Express, after a long while, it was 2 and half minutes, on the browser, it shows the following message:
    An unhandled exception occurred while processing the request
    Timeout Exception: The Angular CLI process did not start listening for requests within the timeout period of 0 seconds. Check the log output for error information
    this is because the Angular CLI did start in time of the client request, you can simply, click on “refresh” button on your browser”
  11. Step 10: click on refresh button on the browser, after a few seconds, you should be presented with the Angular “Hello, Word!” page. 
  12. Step 11: click on <Fetch data>, <Counter> tabs, you verify the app is working as expected.
Up to here: coagulations,   you have successfully upgraded you Angular app from version 8 to version 9! 

Saturday, November 21, 2015

difference between architect and developer

As we see things, an architect is, among other things, a better and more experienced developer. We don’t believe there’s value in having architects who just speak in UML and Visio and leave any implementation details to developers. At least, we’ve never found it easy to work with these people when we’ve crossed paths with them. 

Dino Esposito & Andrea Saltarello in “Microsoft .Net Architecting Applications for the Enterprise”

I am a big believer on "an architect is a better and more expereicned developer”. but what characteristics separate an architect from his fellow experienced developers? 

an experienced developer know how, and an architect know why besides know how.

in my working experience I came across an “architect”, for the convenience of writing, let’s call him G, G knows how to do lots of stuff, among all he knows, he is a big fan of “Software factory”. the other buzz words often seen in his writing are “unit test, dependency injection, architecture governance, spec catalogs …” he favors code generation over well designed code using inheritance, abstraction, encapsulation and polymorphism. let alone SOLID principles. with him as the “lead Architect” the technologies were implemented into the system. but those technologies did not deliver the timeline he promised, the project overrun original timeline more than 100%.  there is nearly no unit cases in the codebase as he promised when he introduced “Dependency Injection’. the last time I checked was the project is close to be aborted by the client and his last technic he deployed was “blame the developers” 
an experienced developer might know how to implement dependency injection using Unity or Ninject, but he might not know when to use it to deliver business value. an qualified architect should know. 
an experienced developer might know how to implement spec catalog, but he might not know what kind of code the factory should generate. a qualified architect should know.

An experienced developer knows how to implement the techniques  and an architect knows how to drive to those technical decisions based the requirement.

in my working experience I came across an lead developer, for convenience of writing, let’s call him J, I wanted to develop J's architect skills, so in a small project I position myself as “Product owner” and position J as the “architect”. In this setting, I make requirement related decisions and he makes architecture decisions.  this is what happened during the project:

while there is a developer working on database schema,  J decided to ask another developer to work on Entity Framework using “Code First” pattern.
when the database developer changed the database model based on UX design instead of entity relationship, asking him reviewed the new database model and his response is “it looks good” before even reading the requirement document.
on the other end, he instructed the team to implement Unity  for dependency Injection, without knowing what requirement it is address to.

this reminded me what Dino and Andrea said about what an architect does in their book “Architecting Applications for the Enterprise”. 

  • Acknowledging the Requirements
  • Breaking down the system
  • Identifying and Evaluating Technologies 
  • Formulating Specifications 

Among 4 major responsibilities of an architect, number one of them is acknowledging the requirement.  all architecture decisions must be driven from requirement, functional and nonfunctional alike.  All team members, especially the architect need to read the requirement document and fully understand what they mean to the system. 
Approving data model changes without understanding the business domain entity model, is not a qualified Architect should do.
“Code First” might be a cool technology, but it needs to fit into the team structure,
“Dependency Injection” is certainly a cool technology, but implementing it without knowing what requirement it is addressing is not a cool thing to do for a qualified architect.

Monday, February 16, 2015

int.TryParse and CA1806


I have a method coded as following:

public int ConvertDirect(string input)

        {
            int result;
            int.TryParse(input, out result);
            return result;
        }

And when I ran the code analysis I got the following warning:

CA1806 Do not ignore method results
'Class1.ConvertDirect(string)' calls 'int.TryParse(string, out int)' but does not explicitly check whether the conversion succeeded. Either use the return value in a conditional statement or verify that the call site expects that the out argument will be set to the default value when the conversion fails.

I then did a google search on int.TryParse  and found that when the conversion failed, zero is output to the out parameter. And this is what I want it to do. So technically speaking, the code block at the question is doing what I want it to do. There is nothing wrong about it.

So I went to suppress it. By doing so I added an attribute to the method. The method become the following.

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1806:DoNotIgnoreMethodResults", MessageId = "System.Int32.TryParse(System.String,System.Int32@)")]

        public int ConvertDirect(string input)
        {
            int result;
            int.TryParse(input, out result);
            return result;
        }

I felt uncomfortable about the suppression I just did.  The fact is that by doing what I am doing here, if I make another call to another function and ignore the result. Even if it could produce unintended result, it would be also suppressed as the suppression is done in the member level. But I also do not want to write more code. With that I was settled with the following code block

public int Convert(string input)
        {
            int result;
            return (int.TryParse(input, out result) ? result : 0);
        }

With I ran the code metrics, I get 3 lines for the original version and I got 2 lines for the modified version of the method. On the other side, I got 2 Cyclomatric Complexity for the modified version and only got 1 Cyclomatric Complexity for the original version of the method. But on the maintainability aspect, the modified version offers 84% in maintainability index while the original version of the method offers 81% in in maintainability index. Considering all aspects mentioned above, I am in favor of the modified version. How about you?

 public int Convert(string input)

        {
            int result;
            return (int.TryParse(input, out result) ? result : 0);
        }


Another option is to provide a extension method just do the conversation. but as the input parameter is of string type, the extension method must be made on string type. as such, the name of the method need to indicate the target type it try to parse. (TryParseToInt)  this raise another naming warning. "CA1720: Identifiers should not contain type names"

IMHO,  the best solution would be  Microsoft add a static method in int class, TryParseWithDefault or it changes the implementation of Parse so that it does not throw exception when parsing failed, instead it provide default value as output.

CA2204 in Visual Studio 2013


From this link, you will find that CA2204 Literals should be spelled correctly 


is categorized as Usage Warning.
 

From the screen shot above, you can also find it is categorized as naming Warning 

If you did not spend much effort try to export  CA warnings into database to further process them you may not notice the discrepancy between IDE and the MSDN documentation. 

But if you plan to capture them and store them in a SQL/Server database, you may want to know this discrepancy. For me, in order to make the metrics generated from my database matches to the metrics produced by Visual Studio, in my database I set CA2204 as naming warning. 

Not a big deal, but it took me a while to figure out the root cause of the discrepancy between my database and the IDE, I thought it would be great if MS keep them align to each other.

Thursday, December 11, 2014

Who is or who is not Architect


The following is a dialog between 2 individuals with the job title of Enterprise Application Architect. Let’s call  them A1 and A2:

 

A1: what are the CA warnings? What is the road map to eliminate them?

A2: let me send you an link from MSDN on these warnings. Microsoft did a good job on providing root cause, description, how to fix it and so on…

A1: do not give me work to do,  I am not going to read them all. I am an enterprise Architect, I only care about the enterprise architect at the high level.

A2: let me give you an example of CA warnings, CA1704 identifiers should be spelled correctly. The description is “The name of an externally visible identifier contains one or more words that are not recognized by the Microsoft spelling checker library”

A1: what is the methodology to fix this type of warnings?

A2: you correct the spelling of the identify to make them confirm to English dictionary.

A1: what, it has to be in correct English spelling? It is just a variable name, I can name it in any way I want!

A2: in modern programming, identifies ( class, property, method, local variables) need to be named following Pascal or camel name standard with proper English spelling of the wards. Failure in doing so would  result in this Code Analyses warnings.  If our programmers thought the way you think, we would have much more warnings than we do now.

A1: How to fix it then?

A2: let me show you an example on how to fix them, ( open up Visual Studio with the project opened)…

A1: I do not want to see Visual Studio, I just want to know methodology or road map on how to fix them

A2: that is what I plan to show you how I fix it as a programmer working on the code

A1: I am an Enterprise Architect,  do not show me these detail stuff

A2: (do not know what to say)

M1: A2, do you know what to do after this meeting? Do you know what A1 wants?

A2: I am confused, based on what I know on the subject, what I have provided is what he needs, it is just that he does not understand what I wrote. If you show what I have here to any software developer,  they would understand what I mean and able to follow what I wrote here to do what he or she needs to do. It I just A1 does not understand the business we are in…

M1: A2, since you did not provide what A1 asking for, and unable to provide the solution A1 is asking for. I will get someone who can…

A2:  I am not sure A1 knows what he is asking for or what he asks for even exist..

The conversation ends then, my friend (A2)  told me with frustration on his face…


This reminded me a book I read a year ago, the title is “Microsoft .NET: Architecting Applications for the Enterprise”. In the book the author wrote the following on who “architect” is…

 
every architect is a born developer. To take the metaphor one step further, we could say that the class Architect inherits from the class Developer and adds some new methods (skills) while overriding (specializing) a few others. Becoming an architect is the natural evolution in the career of some developers. The basic differences between an architect and a developer are experience and education. You gain experience by spending time on the job; you earn your education from studying good books and taking the right classes. In addition, an architect has the ability to focus her vision of the system from a higher level than an average developer… As we see things, an architect is, among other things, a better and more experienced developer. We don't believe there's value in having architects who just speak in UML and Visio and leave any implementation details to developers. At least, we've never found it easy to work with these people when we've crossed paths with them.


According to ISO/IEC, there are not various types of architects. An architect is an architect. Period.
 
It is fine to have multiple architects on the same project team. Likewise, it is fi ne, if not desirable, that different architects have slightly different skills. But they remain just architects, working on the same team on the design of the same system. And architects also have a significant exposure to code. They work out the design of the system but then work closely
with developers to ensure proper implementation. 
With that, I couldn’t help by asking, is A1 really an architect?  An enterprise architect in .Net project, does not know how to operate Visual Studio non wants to look at Visual Studio, What value this type of architect can offer to the project?

Sunday, November 30, 2014

Anti Pattern for December Fast Beats Right


The title of the anti-pattern is Fast Beats Right. The sub title is “A few hours? We don’t have that long”

The elaboration is read as: The practices of rushing a project and taking shortcuts to meet a delivery deadline, usually resulting in poor quality work that will require more effort to maintain in the future


This link provides some further reading on the anti-pattern ( including an interesting photo). For your convenience I quote it as following:

The Fast Beats Right ant-pattern alleges that it is always better to just get something done, regardless of quality, than to invest any effort into doing the job right.  In software development, this quickly leads to taking on Technical Debt, which can be useful and worthwhile in order to meet short-term deadlines.  However, unless it is paid down quickly, its long-term consequences can eventually lead to project failure.

Quotes


"There's never enough time to do it right, but always enough time to do it over." - Jack Bergman

In my decades of software development career, I realized that the some of those who practices this anti-pattern did so intentionally. They just want to get things done and do not want to invest time and effort to do it right. I have seen many in project leadership position do so intentionally.  The long lasting effect to the project is devastating. At the end of it, the project will pay back the technical debt  with interest, sometime it could means failure of the project. There are also people who did so  unintentionally, Due to lack of knowledge and or discipline in software development , programming,  they did what they know how to do, but not necessary the best way. If you ask them why they did what they did, likely you will get response “I do not have time for it, I was in the rush. In order to do what you are talking about, I need more time.” The reality is that even if you give him the time he is asking for, he would not know how to make use of the time and produce better result. “I need more time” is nothing more than an “convenient excuse”

This remind me watching adults playing chess when I was a kid. They took time to think and think,  in most of time, my patients s ran out before they made next move.  I thought I got the next move way before they do…. But when my daddy one day agreed to play the game with me, I lost the game terribly, When daddy asked me to time more time to think before making move, I realized I do not know how to use the extra time to think, what to think, how to think. I end up still making bad move. To use the time effectively one need to be skillful and knowledgeable. The same is true in software programming.  Less qualified developers meet with less qualified architects , project managers will likely result in “Fast Beats Right”  and “Fast Beats Right” will likely result in more difficult down the road, or even the failure of the project. At the end of it  have needing to "do it over"