Git Product home page Git Product logo

sobo's People

Contributors

linusostlund avatar

Watchers

 avatar

sobo's Issues

S1481

๐Ÿค– : Hi @user

๐Ÿค– : You posted a new commit! Keep up the hard work. You are doing great ๐Ÿ˜„

๐Ÿค– : Hey! I'm SOBO, your annoying but well-intentioned bot-friend from INDA

๐Ÿค– : I notice that in the following file(s) in the specific line(s), there is(are) a few violations regarding the same rule

Line File
5 src/pokemon/fire.java
18 src/pokemon/fire.java
25 src/pokemon/water.java

โš ๏ธ Violation : S1481 -- Unused local variables should be removed

๐Ÿค– : My primary mission here is to help you to improve your code quality...

๐Ÿค– : I know that making your code compile might represent enough challenge for you already, but believe me when I say that small changes can boost your work.

๐Ÿค– : Have I told you before about Maintainability?

Maintainability:

User case
- You are in charge of the *maintenance of lifts* a building company, and you are asked to work on the elevators in Tekniska Hogskolan...
- You have a widespread routine and have done this several times ... easy cake, right? 
- But, this time, you see a long red cable hanging out of the back part of the door. 
- You think: "I know this should be part of the electric system and shouldn't be a problem, but why is that cable hanging there?
- Because of safety, you must request an expert consult, which takes three more days than expected.
- Then you received the expert report, which says that the cable wasn't connected to anything at all, and it didn't present a risk but wasn't used.

Now, this is what can happen with unused variables.

In software development, time and resources are precious. Therefore, using good practices in your code makes the software maintainable, allowing other developers to understand your code easily. Therefore they will use their time mostly on their specific task, which might be fixing a bug or adding new functionalities.

An example of what to do :

Instead of doing this

  /**
   * We want to count the number of sheep in a list 
   * */
    public static int countingSheeps( List<String> herd){
        int wolfs=0;
        int sheeps=0;
        for (int i=0;i<herd.size();i++){
            if (herd.get(i).equals("sheep")){
                sheeps++;
            }
        }
        return sheeps;
    }

Do this :

    public static int countingSheeps( List<String> herd){
        int sheeps=0;
        for (int i=0;i<herd.size();i++){
            if (herd.get(i).equals("sheep")){
                sheeps++;
            }
        }
        return sheeps;
    }

๐Ÿค– : I know this looks simple, and that's my point of being here!

๐Ÿค– : Good quality code starts one step at a time

๐Ÿค– : Try always to keep your task clean, and after several changes, make sure you don't have unused variables. This won't only help others but yourself in your successful CS career.

โ“ Curious fact: -1, 0, and 1 are not considered magic numbers ๐Ÿ˜ฑ

๐Ÿค– : Hope to hear from you soon! ๐Ÿ˜‰

๐Ÿค– : And never forget that "Good programmers write code that humans can understand." Martin Fowler.

S1155 v2

๐Ÿค– : Hi @user

๐Ÿค– : You posted a new commit! Keep up the hard work. You are doing great ๐Ÿ˜„

Unfortunately, our SOBO-bot found a few violations that you might want to check out ๐Ÿค”

โš ๏ธ Violation : S1155 -- Collection.isEmpty() should be used to test for emptiness

๐Ÿค– : Hey! I'm SOBO, your annoying but well-intentioned bot-friend from INDA

๐Ÿค– : I notice that in the following file(s) in the specific line(s), there is(are) a few violations regarding the same rule!

Line File
5 src/pokemon/fire.java
18 src/pokemon/fire.java
25 src/pokemon/water.java

๐Ÿค– : To understand this violation is essential to go through the concepts of code READABILITY and COMPLEXITY in our code... ๐Ÿค“

READABILITY : This concept refers to how easy your code is to read. This concern many topics like the name of variables, documentation, etc. In this case, calling the method .isEmpty() will set a clear message about what you are interested in checking, while asking for the size might lead to misunderstanding, and it could be prone to errors.

COMPLEXITY: In simple words, we will refer to complexity as the number of operations performed by your code. The more operations, the more complex our code is, and more resources will be taken from our machine. Now you are doing more simple tasks which don't require too many resources. Still, in your rockstar programmer future this would become very relevant, and I suggest you practice from the beginning.
In this case the complexity of .isEmpty() should be O(1), the smallest, and the method .size() can be bigger.

To become PRO-programmers, your code should try to be easy to understand, so even if you don't completely understand the concept of complexity, we must try to keep it as low as possible.

So, when you want to know if a collection is empty:

Instead of doing this

if (myCollection.size() == 0) {  
  /* ... */
}

Do this:

if (myCollection.isEmpty()) {
  /* ... */
}

Using Collection.size() to check if your collection is empty will work, but using Collection.isEmpty() will be more accurate (Rockstar) .

โ“ Curious fact: Many classes and objects in Java have util methods that help us reduce our code complexity ๐Ÿ˜ฑ. Working whit big integers might be a problem sometimes, and one difficulty is to decide if they are or not prime numbers. Java has an inbuilt isProbablePrime() method in BigInteger class. It returns true if this BigInteger is probably prime(with some certainty) and false if it's definitely composite.

๐Ÿค– : Now you know what to do. Should we give it a new try? ๐Ÿ˜„

๐Ÿค– : Can't wait to see your next commit ๐Ÿ˜‰

S1155

Hi @user! I'm SOBO, your annoying but well-intentioned bot-friend from INDA. I notice that in the following file(s), in some specific line(s), there are a few violations regarding the same rule:

โš ๏ธ Violation : S1155 -- Collection.isEmpty() should be used to test for emptiness

Line File
5 Fire.java
18 Fire.java
25 Ice.java

โ›”๏ธ Instead of doing this:

if (myCollection.size() == 0) {  // might introduce bugs!
  /* ... */
}

โœ… Do this:

if (myCollection.isEmpty()) { // *perfect* ๐Ÿ‘Œ
  /* ... */
}

While Collection.size() == 0 might work, there is a coding convention to use Collection.isEmpty(). This makes your code more readable and reduces the possibility of unwanted side effects. I have provided some notes on readability and complexity for you!

๐Ÿ“š Readability

This concept refers to how easy your code is to read. Readability concern topics ranging from the name of variables and methods to documentation. In this case, calling the method .isEmpty() will set a clear message about your intention. Checking the size of your list might lead to confusion when an outside programmer reads your code. It could also be prone to errors.

Becoming a professional programmer involves courtesy, so writing clear and understandable code should always be on top of your mind!

๐Ÿ“š Complexity

Complexity is the number of operations performed by your code. The more operations, the higher complexity of your code. A code with high complexity requires more resources from your computer. Checking if your list is empty should require at most one operation. You risk having more operations when you use the .size() method.

โ“ Curious fact

Many classes and objects in Java have util methods that help us reduce our code complexity ๐Ÿ˜ฑ. Working with big integers might be a problem sometimes, and one difficulty is to decide if they are or not prime numbers. Java has an inbuilt isProbablePrime() method in BigInteger class. It returns true if this BigInteger is prime (with some certainty) and false if it is definitely composite.

I hope you learned something from my message ๐Ÿ˜„ Remember, put an educational quote here.

Why am I receiving this?

Link to repo README.me that explains what and why.

S109

๐Ÿค– : Hi @{}

๐Ÿค– : It's me, SOBO !
๐Ÿค– : You posted a new commit! Keep up the hard work. You are doing great ๐Ÿ˜„
๐Ÿค– : I notice that in the following file(s) in the specific line(s), there is(are) a few violationsregarding the same rule!

โš ๏ธ Violation: S109 -- Magic Number shouldn't be used

Line File
5 src/pokemon/fire.java
18 src/pokemon/fire.java
25 src/pokemon/water.java

๐Ÿค– : This has an easy fix, but it is essential to know why it is a bad idea to use it ๐Ÿค”

A magic number is a number that โœจcomes out of nowhereโœจ, and in a hurry, no one cares about this (even I do it sometimes), BUT when you come back to your repo after one thousand days, you probably will not remember why you use it or it could lead to awful headaches when debugging. For this reason, we suggest defining the variable and then using it. Here is an example:
Instead of doing this

        public class Example{
            public static void doSomething() {
                for(int i = 0; i < 4; i++){               
                    ...
                }
            }   
        }
        
    **Do this:**
        public class Example{
            public static final int NUMBER_OF_CYCLES = 4;
            public static void doSomething() {
                for(int i = 0; i < NUMBER_OF_CYCLES ; i++){
                    ...
                }
            }
        }

โ“ Curious fact : -1, 0 and 1 are not considered magic numbers ๐Ÿ˜ฑ

๐Ÿค– : Now you know what to do. Should we give it a new try? ๐Ÿ˜„

๐Ÿค– : Can't wait to see your next commit ๐Ÿ˜‰

S109 v2

Hi @user

Congratulations, your code compiles!! ๐ŸŽ‰ ๐Ÿฅณ

Hey! I'm SOBO ๐Ÿค– your annoying but well intentioned bot-friend from INDA. After analyzing your code, I found that you have some violations regarding the following rule(s):

โš ๏ธ Violation : S109 -- Magic Number shouldn't be used

Line File
5 Fire.java
18 Fire.java
25 Ice.java

Press the link for exact position!


This has an easy fix, but it is important to understand why it is a bad practice. Magic numbers are numbers that are used in your code without any explanation. This can lead to confusion and bugs. It is easier to understand with an example:

โ›”๏ธ Instead of doing this

public class Example{

    /* Foo method */
    public static void foo() {
        // '4' is a magic number ๐Ÿ˜ฑ๐Ÿช„
        for(int i = 0; i < 4; i++){            
            ...
        }
    }   
}

โœ… Do this:

public class Example {
    // in java, constants are written in UPPER_CASE
    public static final int NUMBER_OF_CYCLES = 4; 

    /* Foo method */
    public static void foo() {
        // ah, it's the number of cycles!
        for(int i = 0; i < NUMBER_OF_CYCLES ; i++){
            ...
        }
    }
}

...

โ“ Curious fact : -1, 0 and 1 are not considered magic numbers ๐Ÿ˜ฑ

So that's it! I hope you learned something from my message ๐Ÿ˜„ Remember, put an educational quote here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.