Skip to content

Language Groups

A LanguageGroup contains all challenge groups for a single programming language. Each ReadingBatContent instance has three language groups: java, python, and kotlin.

Language Properties

Each language has built-in defaults:

Language Suffix Default srcPath Quote Style
Java .java src/main/java Double quotes
Python .py python Single quotes
Kotlin .kt src/main/kotlin Double quotes

Java Language Group

Java challenges have the simplest syntax because return types are inferred from source code:

val javaLanguageGroup =
  readingBatContent {
    repo = FileSystemSource("./")

    java {
      srcPath = "src/main/java"

      group("Warmup-1") {
        packageName = "warmup1"
        description = "Simple warmup problems"
        includeFiles = "*.java"
      }

      group("String-1") {
        packageName = "string1"
        description = "Basic string problems"
        includeFiles = "*.java"
      }

      group("Array-1") {
        packageName = "array1"
        description = "Basic array problems"
        includeFiles = "*.java"
      }
    }
  }

Java groups use includeFiles (not includeFilesWithType) because the return type is derived from the method signature at parse time.

Python Language Group

Python challenges require explicit return types via the returns infix function:

val pythonLanguageGroup =
  readingBatContent {
    repo = FileSystemSource("./")

    python {
      srcPath = "python"

      group("Warmup-1") {
        packageName = "warmup1"
        description = "Simple warmup problems"
        includeFilesWithType = "*.py" returns BooleanType
      }

      group("String-1") {
        packageName = "string1"
        description = "String manipulation challenges"
        includeFilesWithType = "*.py" returns StringType
      }

      group("List-1") {
        packageName = "list1"
        description = "List manipulation challenges"
        includeFilesWithType = "*.py" returns IntType
      }
    }
  }

Python requires includeFilesWithType

Using includeFiles for Python challenges will throw an error. Python's dynamic typing means the return type cannot be inferred from source code alone.

Kotlin Language Group

Kotlin challenges also require explicit return types:

val kotlinLanguageGroup =
  readingBatContent {
    repo = FileSystemSource("./")

    kotlin {
      srcPath = "src/main/kotlin"

      group("Warmup-1") {
        packageName = "warmup1"
        description = "Simple warmup problems"
        includeFilesWithType = "*.kt" returns StringType
      }

      group("Functional-1") {
        packageName = "functional1"
        description = "Functional programming challenges"
        includeFilesWithType = "*.kt" returns IntType
      }
    }
  }

Per-Language Repository

Each language group can specify its own repository source, independently of the top-level repo setting:

val perLanguageRepoContent =
  readingBatContent {
    java {
      repo = GitHubRepo(Organization, "readingbat", "readingbat-java-content")
      branchName = "main"

      group("Warmup-1") {
        packageName = "warmup1"
        includeFiles = "*.java"
      }
    }

    python {
      repo = GitHubRepo(Organization, "readingbat", "readingbat-python-content")
      branchName = "main"

      group("Warmup-1") {
        packageName = "warmup1"
        includeFilesWithType = "*.py" returns BooleanType
      }
    }
  }

Configurable Properties

Property Type Default Description
repo ContentRoot Inherited from ReadingBatContent.repo Content source (local or GitHub)
branchName String Inherited from ReadingBatContent.branchName Git branch for remote content
srcPath String Language-specific default Source directory path within the repo