qinjinjia / ec601_Code-Review2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EC601_Code Review 2:mag:

Brief Introduction 😎

Hello Everyone! :trollface::trollface::trollface::trollface:

This is the page for EC601(Fall 2017) A1 Code Review 2 Assignment ➿

The page for EC601(Fall 2017) A1 Code Review 1 Assignment can be found HERE ➿

The Code Review 2 follows the same criteria as the Code Review 1 .

The project reviewed @github.com/kev5/Go-Meet
The Reviewer πŸ‘¦ Qinjin Jia qjia@bu.edu πŸ‘‰@github/qinjinjia
Criteria Followed MIT 6.005 fall 15 - Reading 4 Code Review
Code Review Checklist

🌞 Summary of the Code Review Criteria πŸ”— Code Review Criteria.pdf

🌝 Code Review auxiliary tool: jslint, pep8, pylint

Overall

🌚 This is an exciting project Go & Meet. The project is essentially a social/recreational application which gives information of all the events (public/private) happening in the local vicinity of the user on a real-time basis.

πŸŒ‘ The Github Repository of the Project Go & Meet becomes more abundant. There are some new files:file_folder: are added into the repository.

πŸŒ’ There is a ReadMe file in the repository, which is perfect. However, there are many files in the Repository and GitHub file structure and directory structure is not clearly understandable. It seems that it is because the project is still under development 🚧.

πŸŒ“ There are ten java files I reviewed in Code Review 1:

File Name Link
ChooseLoginRegistrationActivity.java πŸ”— ChooseLoginRegistrationActivity.java
Community.java πŸ”— Community.java
Database.java πŸ”— Database.java
LoginActivity.java πŸ”— LoginActivity.java
MainActivity.java πŸ”— MainActivity.java
Post.java πŸ”— Post.java
RegistrationActivity.java πŸ”— RegistrationActivity.java
User.java πŸ”— User.java
readFromFireBase.java πŸ”— readFromFireBase.java
writeToFireBase.java πŸ”— writeToFireBase.java

πŸŒ– There are five java files and four python files I reviewed in Code Review 2:

File Name Link Comments
ChooseLoginRegistrationActivity.java πŸ”— ChooseLoginRegistrationActivity.java Revised since Code Review 1
Database.java πŸ”— Database.java Revised since Code Review 1
LoginActivity.java πŸ”— LoginActivity.java Revised since Code Review 1
MainActivity.java πŸ”— MainActivity.java Revised since Code Review 1
RegistrationActivity.java πŸ”— RegistrationActivity.java Revised since Code Review 1
boston_crime.py πŸ”— boston_crime.py New Added
csv2json.py πŸ”— csv2json.py New Added
wikidata_get.py πŸ”— wikidata_get.py New Added
zipcodeData.py πŸ”— zipcodeData.py New Added
Community.java πŸ”— Community.java Removed before Code Review 2
Post.java πŸ”— Post.java Removed before Code Review 2
User.java πŸ”— User.java Removed before Code Review 2
readFromFireBase.java πŸ”— readFromFireBase.java Removed before Code Review 2

Code Review2

1. Code Formatiing

All python files are assessed by the Code Review auxiliary tool: pep8 and pylint for an overview of the code quality.

Python File Name Link pep8 check pylint check
boston_crime.py πŸ”— boston_crime.py 25 Problems 4.59/10
csv2json.py πŸ”— csv2json.py 7 Problems 3.75/10
wikidata_get.py πŸ”— wikidata_get.py 9 Problems -3.16/10
zipcodeData.py πŸ”— zipcodeData.py 5 Problem 3.16/10

PEP8 Example: PEP8 check for boston_crime.py

boston_crime.py:9:43: E251 unexpected spaces around keyword / parameter equals
boston_crime.py:9:45: E251 unexpected spaces around keyword / parameter equals
boston_crime.py:17:80: E501 line too long (96 > 79 characters)
boston_crime.py:20:20: E261 at least two spaces before inline comment
boston_crime.py:20:20: E262 inline comment should start with '# '
boston_crime.py:25:1: E302 expected 2 blank lines, found 1
boston_crime.py:30:12: E231 missing whitespace after ','
boston_crime.py:32:13: E201 whitespace after '('
boston_crime.py:32:31: E202 whitespace before ')'
boston_crime.py:33:20: E221 multiple spaces before operator
boston_crime.py:36:1: W293 blank line contains whitespace
boston_crime.py:47:21: W291 trailing whitespace
boston_crime.py:48:38: E231 missing whitespace after ','
boston_crime.py:69:12: E231 missing whitespace after ','
boston_crime.py:72:14: W291 trailing whitespace
boston_crime.py:76:70: W291 trailing whitespace
boston_crime.py:79:14: W291 trailing whitespace
boston_crime.py:86:80: E501 line too long (259 > 79 characters)
boston_crime.py:88:1: W293 blank line contains whitespace
boston_crime.py:89:1: W293 blank line contains whitespace
boston_crime.py:91:43: E251 unexpected spaces around keyword / parameter equals
boston_crime.py:91:45: E251 unexpected spaces around keyword / parameter equals
boston_crime.py:92:60: E251 unexpected spaces around keyword / parameter equals
boston_crime.py:92:62: E251 unexpected spaces around keyword / parameter equals
boston_crime.py:92:76: W292 no newline at end of file

Pylint Example: Pylint check for boston_crime.py

************* Module boston_crime
C:  9, 0: No space allowed around keyword argument assignment
f3 = open("zip_pos_us.csv", 'rt', encoding = 'latin-1')
                                           ^ (bad-whitespace)
C: 30, 0: Exactly one space required after comma
    for key,value in zip_boston_pos.items():
           ^ (bad-whitespace)
C: 32, 0: Unnecessary parens after 'if' keyword (superfluous-parens)
C: 32, 0: No space allowed after bracket
        if ( distance < lenmin ):
           ^ (bad-whitespace)
C: 32, 0: No space allowed before bracket
        if ( distance < lenmin ):
                               ^ (bad-whitespace)
C: 33, 0: Exactly one space required before assignment
            zipcode  = key
                     ^ (bad-whitespace)
C: 36, 0: Trailing whitespace (trailing-whitespace)
C: 47, 0: Trailing whitespace (trailing-whitespace)
C: 48, 0: Unnecessary parens after 'in' keyword (superfluous-parens)
C: 48, 0: Exactly one space required after comma
        for key, value in (zip(header,row)):
                                     ^ (bad-whitespace)
W: 49, 0: Bad indentation. Found 16 spaces, expected 12 (bad-indentation)
C: 69, 0: Exactly one space required after comma
    for key,value in d.items():
           ^ (bad-whitespace)
C: 72, 0: Trailing whitespace (trailing-whitespace)
C: 76, 0: Trailing whitespace (trailing-whitespace)
C: 79, 0: Trailing whitespace (trailing-whitespace)
C: 86, 0: Line too long (259/100) (line-too-long)
C: 88, 0: Trailing whitespace (trailing-whitespace)
C: 89, 0: Trailing whitespace (trailing-whitespace)
C: 91, 0: No space allowed around keyword argument assignment
json.dumps(dict(boston_crime_data_from2015 = data))
                                           ^ (bad-whitespace)
C: 92, 0: Final newline missing (missing-final-newline)
C: 92, 0: No space allowed around keyword argument assignment
print(json.dumps(dict(boston_crime_data_from2015_statistics = crime_stat)))
                                                            ^ (bad-whitespace)
C:  1, 0: Missing module docstring (missing-docstring)
C:  5, 0: Invalid constant name "f1" (invalid-name)
C:  6, 0: Invalid constant name "reader1" (invalid-name)
C:  7, 0: Invalid constant name "f2" (invalid-name)
C:  8, 0: Invalid constant name "reader2" (invalid-name)
C:  9, 0: Invalid constant name "f3" (invalid-name)
C: 10, 0: Invalid constant name "reader3" (invalid-name)
C: 12, 0: Invalid constant name "zip_boston" (invalid-name)
C: 13, 0: Invalid constant name "zip_boston_pos" (invalid-name)
W: 29, 4: Redefining name 'zipcode' from outer scope (line 39) (redefined-outer-name)
W: 30, 8: Redefining name 'key' from outer scope (line 48) (redefined-outer-name)
W: 30,12: Redefining name 'value' from outer scope (line 48) (redefined-outer-name)
C: 25, 0: Missing function docstring (missing-docstring)
C: 37, 0: Invalid constant name "data" (invalid-name)
C: 38, 0: Invalid constant name "header" (invalid-name)
C: 39, 0: Invalid constant name "zipcode" (invalid-name)
C: 42, 7: Do not use `len(SEQUENCE)` as condition value (len-as-condition)
W: 46, 8: No exception type(s) specified (bare-except)
C: 58, 0: Invalid constant name "crime_stat" (invalid-name)

-----------------------------------
Your code has been rated at 4.59/10

According to the Code Review auxiliary tool Pep8 and Pylint, Overall Code Quality(Formatting) is OK.

1.1 Alignments

For all java files revised after Code Review 1 and all new added python files, the uses of alignments are perfect. The code block starting point and ending point are easily identifiable.

1.2 Naming Conventions

The β€˜camelCode’ nameing convention is used in the project. The developers utilize capital letters to indicate the start of a word, which makes name of variables be meaningful.

1.3 Code Layout

πŸ‘Perfect! The code can fit in the standard 14-inch laptop screen.

1.4 Commented Code

The commented code in Database.java has been deleted (Or removed from the master branch) before Code Review 2.

public class Database {
    public FirebaseDatabase mDatabase;
    public DatabaseReference myRef;
//    public String ID = "690";                <-This commented code should be removed
    public Database(){
    }

and the commented code in MainActivity.java has been removed as well.

        al.add(post01.getPostText());
//        al.add(post02.getPostText());        <-This commented code should be removed
//        al.add(post03.getPostText());
//        al.add(post04.getPostText());
//        al.add(post05.getPostText());
//        al.add(post06.getPostText());

However, it seems that it is because the project is still under development 🚧. There are still some commented code blocks in the project. The commented code in MainActivity.java, for instance.

//    public void postEvent(View view) {
//        view = (LayoutInflater.from(MainActivity.this)).inflate(R.layout.activity_post, null);
//        AlertDialog.Builder alertBuilder = new AlertDialog.Builder(MainActivity.this);
//        alertBuilder.setView(view);
//
//        Dialog dialog = alertBuilder.create();
//        dialog.show();
//
//        alertBuilder.setCancelable(true)
//                .setPositiveButton("GO", new DialogInterface.OnClickListener(){
//                    //private EditText mEventName;
//
//                    @Override
//                    public void onClick(DialogInterface dialog,int which){
//                        mEventName = (EditText) findViewById(R.id.event_name);
//                        final String eventName = mEventName.getText().toString();
//                        final String userId = mAuth.getCurrentUser().getUid();
//                        DatabaseReference postDb = FirebaseDatabase.getInstance().getReference().child("Users").child(userSex).child(userId).child("dd");
//                        postDb.setValue(eventName);
//
//                    }
//                });
//    }

2. Architecture

It seems that the developers follow the Singleton pattern, which is good.

Additionally, code is in sync with existing code patterns/technologies.

Therefore, the architecture of the project is nice.


3. Coding best practices

3.1 Hard Coding

πŸ‘ Good!. There is no hard coding in the project.

3.2 Enumeration

The java file πŸ”— MainActivity.java contains magic number. It is difficult to understand what is the meaning of 1, 2, 3 etc here. This might be solved by utilizing the enumeration.

        mWrite.writePosts("1",post01);
        mWrite.writePosts("2",post02);
        mWrite.writePosts("3",post03);
        mWrite.writePosts("4",post04);
        mWrite.writePosts("5",post05);
        mWrite.writePosts("6",post06);

This issue has been revised before the Code Review 2. πŸ‘ Perfect!

3.3 Comments

There are some to-do comments mention pending tasks, which is good. For instance, in User.java

    public User() {
        // Default constructor required for calls to DataSnapshot.getValue(User.class)
    }

However, this kind of comments(i.e. comments to help developer understand the tutorial) should be deleted (or removed from the master branch).

    public void onLeftCardExit(Object dataObject) {
        //Do something on the left!
        //You also have access to the original object.
        //If you want to use it just cast it (String) dataObject
        Toast.makeText(MainActivity.this, "NOPE!", Toast.LENGTH_SHORT).show();
    }

Additionally, the developers could add some comments to help others understand the code.

3.4 Mul if/else blocks

πŸ‘ Good, there is no multiple if/else block in the project.

3.5 Framework features

N/A


4. Non Functional requirements

4.1 Maintainability(Supportability)

The Readability of the code is good. The team uses β€˜camelCode’ nameing convention, which makes name of variables be meaningful. The project is still under development 🚧, there is no .apk file in the repository, therefore, "Testability", "Debuggability", "Configurability" of the project are not reviewed. Unit test should start before or during the project itself.

4.2 Reusability

Some places in the code violate DRY (Do not Repeat Yourself) principle.Duplicated code is a risk to safety. If you have identical or very similar code in two places, then the fundamental risk is that there’s a bug in both copies, and some maintainer fixes the bug in one place but not the other. For instance, DRY code in πŸ”— writeToFireBase.java

    public void likePost(String postID){
        DatabaseReference commentPostRef = this.writepostRef.child(postID);
        commentPostRef.child("likes").push().setValue(this.user.getUid());
    }

    public void dislikePost(String postID){
        DatabaseReference commentPostRef = this.writepostRef.child(postID);
        commentPostRef.child("dislikes").push().setValue(this.user.getUid());
    }

However, the project utilizes generic functions and classes, which increase reusability of the project.

4.3 Reliability:

Exception handling is not found in the code, which could be considered to add after achieveing the main functions of the software.

4.4 Extensibility

The project utilizes classes and functions, which makes the code has Good Extensibility. The enhancements could be added to the existing code with minimal changes under this design(i.e. classes and functions).

4.5 Security

The developers considered the security of the software, Authentication is addded by utilizing the firebase in LoginActivity.java.

        public void onClick(View v) {
                final String email = mEmail.getText().toString();
                final String password = mPassword.getText().toString();

4.6 Performance

The project is still under development 🚧, there is no .apk file in the repository, therefore, Performance of the project is not reviewed.

4.7 Scalability

The firebase realtime database is utilized as the backend of the porject, which can be found in writeToFireBase.java. The firebase realtime database supports a large user base/data. Therefore, the scalability of the project is good.

    public writeToFireBase(){
        this.user = FirebaseAuth.getInstance().getCurrentUser();
        this.database = FirebaseDatabase.getInstance();
        this.writepostRef = this.database.getReference("posts");
        this.userRef = this.database.getReference("users");
    }

4.8 Usability

The project is still under development 🚧, therefore, Usability of the project is not reviewed.


5. Object-Oriented Analysis and Design (OOAD) Principles

5.1 Single Responsibility Principle(SRS)

The classes in the code are checked, each single class or function has one responsibility. Therefore, the code obeys the Single Responsibility Principle (SRS). Nice design! πŸ‘

5.2 Open Closed Principle

Owing to the developers' good design, each single class or function has one responsibility. While adding new functionality, existing code does not need to be modified. Therefore, the project obeys the Open Closed Principle.

5.3 Liskov substitutability principle

The class hierarchy does not exist in the project. Therefore, the project does not violate the [Liskov substitutability principle](https://en.wikipedia.org/wiki/Liskov_substitution_principle)

5.4 Interface segregation:

The project is still under development 🚧, there is no .apk file in the repository, therefore, Interface segregation of the project is not reviewed.

5.5 Dependency Injection:

The project utilizes firebase to achieve authentication. Dependency injection is not applicable to the project.

Summary

Good Points:

🌝 The overall code quality is high, the design of the software is good. Many issues mentioned in Code Review 1 has been revised. Commented Code Problem, for instance. Thanks πŸŽ‰.

🌚 The project has proper code formatiing,using β€˜camelCode’ nameing convention makes name of variables be meaningful. However, code formatting still can be improved according to the reports from the Code Review auxiliary tool: jslint, pep8, pylint.

πŸŒ‘ The architecture of the project is nice.

πŸŒ’ There are some to-do comments mention pending tasks, which is good.

πŸŒ“ The Readability of the code is good. The developers considered the security of the software, Authentication is addded by utilizing the firebase.

πŸŒ” The project obeys Single Responsibility Principle(SRS), Open Closed Principle and Liskov substitutability principle.

Can be better:

πŸŒ• GitHub file structure and directory structure is still not clearly understandable. It seems that it is because the project is still under development 🚧.

πŸŒ–There are some commented code blocks in the project. The commented code blocks could keep in other branch rather than the master branch. Additionally, the comments that help developer understand the tutorial should be deleted (or removed from the master branch).

πŸŒ— The developers could add some comments to help others understand the code.

🌘 There is no .apk file in the repository, therefore, "Testability", "Debuggability", "Configurability" of the project cannot not reviewed. It is also a good practice to do Unit Test along the code development. Unit test should start before or during the project itself.

🌞 Finally, Good Luck for your project :D)❗

:trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface::trollface:

About