View on GitHub

ashwinjay.github.io

Designing, programming, testing, writing & other useful topics

Ashwin Jayaprakash CC-BY-SA-4.0 (An opinionated collection)

Table of Contents

Created by gh-md-toc

Product development lifecycle

(Keep in mind that the stages are iterative with feedback loops)

Design mnemonics - “FDSCARSS”

(Also see 12 Factor)

Programming basics (Mostly for Java)

Design basics

Documentation and information management

Project maintenance and contributions

Testing and code review

Debugging and problem solving

APIs

Computer fundamentals

Concurrency

Distributed systems

SQL

Cloud

Java

Java/JVM deep dive

Guides, best practices and patterns

Katas

Code generation

Lombok

Restrict its use to the bare minimum.

Misc Java

Dependency Injection

Guice

Stick to explicit Java in all places other than the one place where you bind things.

public class FruitModule extends AbstractModule {
  @Provides
  Apple makeApple(){
   return new Apple();
  }

  @Provides
  @Singleton
  Flour makeFlour(){
   return new WheatFlour();
  }

  @Provides
  ApplePie makeApplePie(Apple apple, Flour flour){
   return new ApplePie(apple, flour);
  }
}

Lifecycle

Style

Visibility

Naming

Member variables

@Getter
@Setter
public class PieRecipe {
    private static final int DEFAULT_FLOUR_GRAMS = 250;

    @NotBlank
    private String name;

    @Min(0)
    private int sugarGrams;

    @Min(100)
    private int flourGrams = DEFAULT_FLOUR_GRAMS;

    @Valid
    private List<Flavor> optionalFlavors;
}

Formatting

Prefer readability over compactness while formatting code. Sometimes the IDE’s automatic formatting may have to be overridden manually.

public BigClass(
        int foo, String bar, float fizz, Object bizz, List<String> names) {
  ...
}

public BigClass(
        int foo, String bar, float fizz, Object bizz, 
        List<String> names, Map<String, Long> moreNames) {
  ...
}

void hello()  {
    world(
      xx, yy, zz, aa, bb, more, stillMore, manyMore, 
      others, moreOthers.values().stream().count()
    );
}

List<Integer> ids = allObjects
          .keySet()
          .stream()
          .filter(foo -> foo > 34)
          .map()
          .collect(Collectors.toList());
          
List<String> items = few
      ? new ImmutableList.Builder()
            .add("foo")
            .add("bar")
            .build()
      : Lists.newArrayList("aa", "bb", "cc", "dd", "ee", "ff", ....);

Ordering of methods

//In unit tests.

@BeforeClass
@BeforeMethod
@AfterMethod
@AfterClass
@Test testXX
@Test testYY
...

Thread safety

Constants

public final class FooBarConstants {
    //"PROP" or "KEY" prefix for property or map keys.
    public static final String PROP_CONFIG_FILE_NAME = "app.config.file";
    
    //"VAL" prefix for fixed property or map values.
    public static final String VAL_DEFAULT_CONFIG_FILE_NAME = "conf/default.properties";
    
    //"VAR" prefix for template strings that can vary slightly.
    public static final String VAR_ERR_MSG_AGE = "The value [%s] provided for 'age' is invalid";
    
    //Private ctor and an abstract class. Prevent sub-classing and instantiation.
    private FooBarConstants() {
    }
}

(Java)Docs, comments and logs

Non-Java files and resources

Prefer non-source code file and directory names like - ~/data-feed/all-lower-case-with-hyphens.csv.

Unit tests

We tend to focus on the “core” parts of the test but often ignore to clarify test boundaries, confirm the absence of unwanted start/end states and test for side effects.

Advanced unit tests

Misc

Learning

“Awesome lists”