linusostlund / sobo Goto Github PK
View Code? Open in Web Editor NEWThings concerning SOBO, a research project in automatic feedback generation at KTH
Things concerning SOBO, a research project in automatic feedback generation at KTH
๐ค : 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 |
๐ค : 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:
- 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.
๐ค : 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) .
๐ค : Now you know what to do. Should we give it a new try? ๐
๐ค : Can't wait to see your next commit ๐
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:
Collection.isEmpty()
should be used to test for emptinessLine | 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!
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 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.
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.
Link to repo README.me that explains what and why.
๐ค : 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!
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 ๐
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):
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++){
...
}
}
}
So that's it! I hope you learned something from my message ๐ Remember, put an educational quote here.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.