Advertisment

Monday, December 5, 2016

A Tutorial: Learn How to Avoid the 10 Most Common Mistakes That C# Developers Make


However, it is incorrect to assume that TryParse is therefore necessarily the “better” method.

 Sometimes that’s the case, sometimes it’s not. That’s why there are two ways of doing it. Use the correct one for the context you are in, remembering that exceptions can certainly be your friend as a developer.

Common Mistake #10: Allowing compiler warnings to accumulate

While this problem is definitely not C# specific, it is particularly egregious in C# since it abandons the benefits of the strict type checking offered by the C# compiler.

Warnings are generated for a reason.  While all C# compiler errors signify a defect in your code, many warnings do as well. What differentiates the two is that, in the case of a warning, the compiler has no problem emitting the instructions your code represents. Even so, it finds your code a little bit fishy, and there is a reasonable likelihood that your code doesn’t accurately reflect your intent.

A common simple example for the sake of this C# tutorial is when you modify your algorithm to eliminate the use of a variable you were using, but you forget to remove the variable declaration. The program will run perfectly, but the compiler will flag the useless variable declaration. The fact that the program runs perfectly causes programmers to neglect to fix the cause of the warning. Furthermore, programmers take advantage of a Visual Studio feature which makes it easy for them to hide the warnings in the “Error List” window so they can focus only on the errors. It doesn’t take long until there are dozens of warnings, all of them blissfully ignored (or even worse, hidden).

But if you ignore this type of warning, sooner or later, something like this may very well find its way into your code:

  class Account {
  
      int myId;
      int Id;   // compiler warned you about this, but you didn’t listen!
  
      // Constructor
      Account(int id) {
          this.myId = Id;     // OOPS!
      }
  
  }

And at the speed Intellisense allows us to write code, this error isn’t as improbable as it looks.

You now have a serious error in your program (although the compiler has only flagged it as a warning, for the reasons already explained), and depending on how complex your program is, you could waste a lot of time tracking this one down. Had you paid attention to this warning in the first place, you would have avoided this problem with a simple five-second fix.

Remember, the C# compiler gives you a lot of useful information about the robustness of your code… if you’re listening. Don’t ignore warnings. They usually only take a few seconds to fix, and fixing new ones when they happen can save you hours. Train yourself to expect the Visual Studio “Error List” window to display “0 Errors, 0 Warnings”, so that any warnings at all make you uncomfortable enough to address them immediately.

Of course, there are exceptions to every rule.  Accordingly, there may be times when your code will look a bit fishy to the compiler, even though it is exactly how you intended it to be. In those very rare cases, use #pragma warning disable [warning id] around only the code that triggers the warning, and only for the warning ID that it triggers. This will suppress that warning, and that warning only, so that you can still stay alert for new ones.

Wrap-up

C# is a powerful and flexible language with many mechanisms and paradigms that can greatly improve productivity.  As with any software tool or language, though, having a limited understanding or appreciation of its capabilities can sometimes be more of an impediment than a benefit, leaving one in the proverbial state of “knowing enough to be dangerous”.

Using a C# tutorial like this one to familiarize oneself with the key nuances of C#, such as (but by no means limited to) the problems raised in this article, will help optimize use of the language while avoiding some of its more common pitfalls.

Source | toptal

Create a Simple Responsive Website Layout using Bootstrap

Creating a responsive website using bootstrap is not  a very complex thing. For that you just need bootstrap installed in your computer. You can download bootstrap from getbootstrap.com. After you have installed bootstrap you can start to create the website layout. Here are the steps to creating the website layout.

1. Create the project folder and name is as BootStrap_Project. But you can give any name if you like.

2. Inside that folder create 2 new folders and name them as css, js.

3. Copy and paste bootstrap.css file into the css folder

4. Copy and paste bootstrap.js file into the js folder

5. Then Download the Jquery file from here and add it to the js file.

6. And create another document and name it as index.html.

7. copy and paste this code inside that index.html document


1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>Blog Template</title>
    <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="css/main.css"/>
</head>
<body>
    <div class="container">
        <div class="row">
            <div class="header">
                <div class="col-xs-12">
                    <!-- header section -->
                    <h2>Header</h2>
                    <span>.col-xs-12</span>
                </div>
            </div>
        </div>
    </div>

    <div class="container">
        <div class="row">
            <div class="sideBar">
                <div class="col-lg-3 col-md-3 col-sm-3 col-xs-12">
                    <!-- sideBar section -->
                    <h2>Side Bar</h2>
                    <span>col-lg-3 col-md-3 col-sm-3 col-xs-12</span>
                </div>
            </div>

            <div class="blogContent">
                <div class="col-lg-9 col-md-9 col-sm-9 col-xs-12">
                    <!-- Blog Content Section -->
                    <h2>Blog Content</h2>
                    <span>col-lg-9 col-md-9 col-sm-9 col-xs-12</span>
                </div>
            </div>

            <div class="footer">
                <div class="col-lg-9 col-md-9 col-sm-9 col-xs-12">
                    <!-- footer section -->
                    <h2>Footer</h2>
                    <span>col-lg-9 col-md-9 col-sm-9 col-xs-12</span>
                </div>
            </div>
        </div>
    </div>



    <script type="text/javascript" src="js/jquery-2.1.4.js"></script>
    <script type="text/javascript" src="js/bootstrap.js"></script>
</body>
</html>


8. Then create another document inside the css folder and name it as main.css

9. Copy this code and paste it inside that document

1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
.container .row .header .col-xs-12 {
    background: none repeat scroll 0% 0% #41c2a8;
    border: 1px solid #367266;
    color: #ffffff;
    font-family: arial;
    text-align: center;
}

.container .row .sideBar .col-lg-3 {
    background: none repeat scroll 0% 0% #feb22e;
    border: 1px solid #a9710f;
    color: #ffffff;
    font-family: arial;
    height: 500px;
    text-align: center;
}

.container .row .blogContent .col-lg-9 {
    background: none repeat scroll 0% 0% #a7db72;
    border: 1px solid #5c8c58;
    color: #ffffff;
    font-family: arial;
    height: 500px;
    text-align: center;
}

.container .row .footer .col-lg-9 {
    background: none repeat scroll 0% 0% #4c74e8;
    border: 1px solid #111e55;
    color: #ffffff;
    font-family: arial;
    text-align: center;
    width: 100%;
}

10. save them all and run the index.html file from your browser. you'll get an output like this.


you can watch this website in mobile view too. it is a complete responsive website layout.


Saturday, December 3, 2016

Integrating Maven to Netbeans, Eclipse and IntelliJ

Mavens popularity has grown in large scale through these years. And many integrated development environments that used with Java, has started to integrate maven with their products.

For example, maven is already setup to integrate with,

  • NetBeans 
  • Eclipse 
  • IntelliJ 
NetBeans Integration 

Starting with the NetBeans 6.7 and higher, there is full Maven support. Using the new projects wizard in NetBeans you can create projects using archetypes in Maven. And the IDE also includes a Maven repository browser that enables the user to view local repository as well as registered external maven repositories. If you have NetBeans versions 6.5 or lower you can add maven by adding the necessary plugins under,

Tools -> Plugins -> Choose Available Plugins -> Choose Maven -> Install and then close.

You can find detailed documentation from wiki.NetBeans.org  . You can find Maven tutorials tips and tricks in NetBeans.

Eclipse Integration 

If you are accustomed to use Eclipse for development. Then you have M2Eclipse version for Maven integration. This can be used to create new Maven projects. And also can handle dependency management. Based on Mavens pom.xml file. Also this perform automatic downloads of required dependencies. 

You can get detailed documentation about M2Eclipse from Eclipse.org/m2e/ .

Go to Help -> Install New Software 

http://download.eclipse.org/technology/m2e/releases/

Enter the above site location in Work with field and press Enter. Then select all the packages and install them. 

IntelliJ Integration 

You can get full Maven support with IntelliJ IDEA from JetBrains. It can be used to import existing projects or create new ones. It has full editing support for the pom.xml files. you can find detailed documentation from JetBrains.com/idea.

To get started with maven just go to IntelliJ IDEA and then create new project and select Maven from there. then go as on...

If you have any questions feel free to post them in comment section.!

Get started with Apache Maven

What is Apache Maven? 

Apache Maven is a Software Project Management and Comprehension tool, Based on the concept of a Project Object Model(POM), Maven can manage a project's build, reporting and documentation from a central piece of information.
-http://maven.apache.org

So basically Apache Maven is a project management tool with  a project object model. And it follows a set of standards. And it includes a projects life cycle. And it also act as  a dependency management system. Maven uses logic for executing plugin goals at life cycle phases. 

With Maven your project follow a consistent structure. And your projects are IDE agnostic. Maven allows for easy modification to the project. Maven simplifies the declaration of project dependencies. And it uses a Project Object Model (POM) as mentioned above. 

Installing and configuring Apache Maven. 

Lets look at how to install and configure apache maven in your computer. 

Before all of the bellow steps ensure that you have installed the latest JDK installed in your computer and (Latest Maven package needs java version 1.7 or higher installed) it is pointed to JAVA_HOME environmental variable.

In Windows  

1. Download the Apache Maven package from here or you can visit http://maven.apache.org. 


2. Then unzip the file and copy the unziped file to the program files in C.

C:\Program Files\
    
3. Then go to system variables and add the bellow path to your system variable paths.  

C:/Program Files/apache-maven-3.3.9/bin

4. Then to see whether maven has installed successfully in your computer open up a command prompt and type mvn -v . and it'll print out something like this.


For Unix Based Operating System (Linux, Solaris or Mac OS X)

check environmental variables 

echo $JAVA_HOME


Add your maven package path


export PATH=/opt/apache-maven-3.3.9/bin:$PATH 

After that open up a new terminal and type mvn -v and you'll get something as mentioned above.


If you have any problems feel free to put them on the comment section.