question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Kotlin Coding Practices

See original GitHub issue

I’m glad to see that you guys have moved onto Kotlin, but a lot of the code still adopts a Java like structure. There are a few things I’m going to bring up for you to consider:

All links are based on the latest commit as of this issue

Why wrap constants in a singleton object? You can just add the values directly on the top level and also add the const keyword so that they are truly constants added where it is used in the byte code.

if (piracyChecker != null) piracyChecker!!.start()

should be

privacyChecker?.start()

Embrace the null operation rather than enforcing non nulls due to using var

The privacy checker as a whole probably shouldn’t be nullable. Just instantiate it lazily so its not done when the check is disabled.

  • System Information
fun checkNetworkConnection(): Boolean? {
    var isConnected = false
    try {
        val process = Runtime.getRuntime().exec("ping -c 1 www.google.com")
        val returnVal = process.waitFor()
        isConnected = returnVal == 0
    } catch (e: Exception) {
        // Suppress error
    }
    return isConnected
}

You can make this return a nonnull Boolean. At the same time, this has an O(1) retrieval time and no parameters. Kotlin’s guidelines would suggest you use the var get() syntax but that is up to you. You also probably shouldn’t use something like this to begin with especially if it is in the ui thread, but I didn’t look any further into it.

A whole bunch of the other functions here all require Context, so use extension functions. And furthermore, none of these should be wrapped in a singleton

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
AllanWangcommented, Jul 13, 2017

I’ll close this issue for now and list whatever things I either don’t get or might be wrong. I’ll submit a PR later for small functions that can be changed without ambiguity.

1reaction
AllanWangcommented, Jul 12, 2017

@nicholaschum Okay I’ll try to make time to push something later today. A few things to note:

Your main purpose for this library is to be able to send an intent for Substratum. Recently (or since last time I checked) you’ve added a bunch of other intents, presumably to help against privacy. I’m not sure if they’re implemented yet so unless there is more info I won’t be adding it.

As for the class, it’s really only meant to launch a function, so I’m going to create an extension function which you’ll see later. I’d say that the majority of themers have their custom ui anyways, so having the extension would make it easier to integrate.

Whether you’d also consider adding a simple UI class as another activity is up to you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Coding conventions
Commonly known and easy-to-follow coding conventions are vital for any programming language. Here we provide guidelines on the code style ...
Read more >
Best Coding Practices in Kotlin 1.4.30
1. Use Sealed Classes Rather Than Exceptions · 2. Don't use Fluent Setters. Use Named Arguments instead · 3. Ad-Hoc Structs · 4....
Read more >
Kotlin style guide
This document serves as the complete definition of Google's Android coding standards for source code in the Kotlin Programming Language.
Read more >
Idiomatic Kotlin. Best Practices. - Philipp Hauer's Blog
Concisely Deal with Nullability · Avoid if-null Checks · Avoid if-type Checks · Avoid not-null Assertions !! · Consider let().
Read more >
Kotlin Android Coding standards
Always import the synthetic layouts for your activity or fragment. This cuts down on an immense amount of boilerplate and keeps your code...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found