Skip to content

Glanzad code review2#27

Open
andrewglanzzz wants to merge 8 commits intomasterfrom
glanzad_CodeReview2
Open

Glanzad code review2#27
andrewglanzzz wants to merge 8 commits intomasterfrom
glanzad_CodeReview2

Conversation

@andrewglanzzz
Copy link
Collaborator

Description of the project:
FreeWays is an application that pulls live traffic / accident data to help you and others stay safe while on the road. It also helps you plan efficient driving routes.

What I learned:
From this code review, I learned quite a bit about cleaning up code. There were quite a few redundancies in the code that I was able to fix and hopefully these suggestions warrant a merge. I also used my previous knowledge of Kotlin naming conventions to fix some various issues that I found within the naming of certain variables. Finally, I learned about function visibility.

@andrewglanzzz
Copy link
Collaborator Author

andrewglanzzz commented Apr 2, 2022

Analysis of the program:
I have already reviewed this program, but my main complaint with the program still persists. It is really difficult to figure out how everything is functioning with the lack of comments. I can tell the code is well written and working since the application builds and functions as expected in its current state, I just found it difficult to make changes to the code itself without knowledge of how it works.

Was the program available in UC Github on time?
Yes.

Is the program documented/commented well enough for you to understand?
Not entirely. As stated earlier, comments are practically non-existent except for a few keys areas. This made code readability somewhat troublesome as I had to figure out how everything worked just by reading the code. Comments would've helped a lot.

Does the program compile?
Yes.

Rationale behind your changes.

Redundancy:
This is somewhat self-explanatory. There were a few lines of code I found throughout the program that had redundancy. These were small mistakes that are easy to make, but I figured I would make the changes in order to slightly decrease technical debt.

Renaming:
I renamed some values to abide by Kotlin naming conventions. This does nothing to reduce technical debt, it was just something that needed to be fixed because in a program with multiple variables that are following naming conventions properly, one that is incorrect sticks out like a sore thumb. I also fixed a typo that I fixed on the last pull request, but my change was not merged and more code was written that utilized the val with the typo, which is odd. I fixed both instances of the typo as a result.

Visibility Modifiers:
hasCameraPermission() and hasExternalStoragePermission() needed to be private in my opinion as they are only being used by MainActivity.kt. When dealing with sensitive permissions, ensuring that the functions that work with these are hidden is important.

Links to three specific commits that you made to your own group's GitHub repository before the end of sprint deadline.
brennerdanae/MyLittleLibrary@ed35436
brennerdanae/MyLittleLibrary@58c5724
brennerdanae/MyLittleLibrary@b88a218

Next, list three specific technical concepts that you learned from this code review.
1.) I learned more about Kotlin naming conventions and when to use each type of naming scheme.
2.) I learned about function visibility and how to properly use the private modifier.
3.) I learned about redundancy within Kotlin and the importance of clearing it.

Sources:
https://kotlinlang.org/docs/coding-conventions.html#function-names
https://kotlinlang.org/docs/visibility-modifiers.html#class-members
https://kotlinlang.org/docs/coding-conventions.html#avoid-redundant-constructs

@JvmField
val AppModule = module {
viewModel { MainViewModel() }
viewModel { MainViewModel(get()) }
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this as per the request of the comment on line 10. If this is unnecessary or not what you meant, omit it please!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the MVM constructor requires a parameter... the question is, does Koin know about the parameter type? Is that also defined in Koin?

Comment on lines +166 to 169
val incidentInfo = Incident().apply {

stateId = 0
stateName = inStateName
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Data within incidentInfo is seems immutable, so I changed it to a val instead of a var.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Default to val. Only use var if you know you need to.

var permissionGranted = false
resultsMap.forEach {
if (it.value == true) {
if (it.value) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed redundancy. == true was not necessary.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

Comment on lines -277 to +278
fun hasCameraPermission() = ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
fun hasExternalStoragePermission() = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
private fun hasCameraPermission() = ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
private fun hasExternalStoragePermission() = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented data hiding on these functions as they are only being used in MainActivity,kt

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good.

firebaseUser = FirebaseAuth.getInstance().currentUser
firebaseUser?.let {
val user = com.ucmobiledevelopment.freeways.dto.User(it.uid, it.displayName)
val user = User(it.uid, it.displayName)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Path was redundant as it was already imported.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes. Good one.


class MainViewModel(var incidentService : IIncidentService = IncidentService()) : ViewModel(){
internal val NEW_INCIDENT = "New Incident"
private val NEW_INCIDENT = "New Incident"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed internal -> private as it is only being used here and is deeply immutable. If you plan on using NEW_INCIDENT somewhere else, ignore this.

Comment on lines -20 to -23
private lateinit var firestore: FirebaseFirestore
private var firestore: FirebaseFirestore = FirebaseFirestore.getInstance()

init{
firestore = FirebaseFirestore.getInstance()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lateinit seemed unnecessary, so I removed the lateinit modifier and got the instance as the var was declared.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either way works. I'd probably go with what the reviewer recommends here.

super.onCreate(savedInstanceState)
setContent {
FreeWaysTheme() {
FreeWaysTheme {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small change, but these parentheses are not necessary here.

val context = LocalContext.current
ExtendedFloatingActionButton (
text = { Text(text = "Back") },
text = { Text(text = "Back") },
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incredibly small change, just removed an extra space because I happened to notice it.

val FATALS: String? = "",
val LATITUDE: String? = "",
val LONGITUD: String? = "",
val LONGITUDE: String? = "",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed typo on LONGITUDE.

newIncident.stateName = it.STATENAME ?: ""
newIncident.latitude = it.LATITUDE ?: ""
newIncident.longitude = it.LONGITUD ?: ""
newIncident.longitude = it.LONGITUDE ?: ""
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed typo on LONGITUDE reference.

if (retrofit == null) {
// create it
retrofit = retrofit2.Retrofit.Builder()
retrofit = Retrofit.Builder()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand this is boilerplate, but specifying retrofit2 is not necessary as it has already been imported.

if(result.Results[0].isNotEmpty()){
result.Results[0].forEach{
val newIncident: Incident = Incident()
val newIncident = Incident()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundancy on newIncident. Shortened it up.

var hasCaseId400434 = false
allIncidents!!.forEach {
if(it.caseId.equals("400434")){
if(it.caseId == "400434"){
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shifted this over to a binary operator to reduce technical debt.

Comment on lines -9 to +15
private val DarkColorPalette = darkColors(
private val darkColorPalette = darkColors(
primary = Purple200,
primaryVariant = Purple700,
secondary = Teal200
)

private val LightColorPalette = lightColors(
private val lightColorPalette = lightColors(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed these to fit Kotlin naming conventions. Camel Case seems appropriate considering the data that these values hold.

Comment on lines -33 to +35
DarkColorPalette
darkColorPalette
} else {
LightColorPalette
lightColorPalette
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the names when called to fix errors caused by renaming.

@discospiff
Copy link

Several good suggestions here that reduce technical debt. I recommend the group merge this branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants