Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Remove void "type"; convert statements to expressions

Aperta
#56 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
20/100
Tipo di issue
Funzionalità
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
java
Ambito
compilers

Direzione di ricerca

Non vengono indicati file, test o punti di ingresso. Inizia esaminando la gestione da parte del compilatore dei tipi restituiti void e delle istruzioni, quindi definisci la semantica del linguaggio e i test necessari per la mutazione fluente, i risultati booleani delle procedure e le definizioni con valore espressione prima dell’implementazione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

proposal

Perhaps we should remove the use of void as a return type. Objects that perform an operation that modify themselves and don't necessarily have something to return can return themselves (similar to the builder pattern).

Example:

aList = [].add(1).add(2).add(3)
print(aList) // [1, 2, 3]

Procedures that aren't related to a class can always return a boolean indicating success or failure. We can even make the lack of a return be considered a success.

Example:

procedure1() {
    a = 10
    b = 10
    c = a + b
    print(c)
}

procedure1() // prints: '20', returns true

procedure2() {
    number = readInt()
    
     // This if "statement" would also technically be an expression that returns a boolean in this proposal
    if (number % 2 != 0) {
        // This can also be an expression maybe?
        return false
    }
}

procedure2() // < 1 returns false; < 2 returns true

It might encourage chaining procedures together like so:

checkCondition1(args) && checkCondition2(args) && checkCondition3(args) && doGuardedProcedure(args)

This is possible in the current state of LJ, but it might be further encouraged if we default return types to boolean (is this something we want to encourage?).

Presumably function definitions and class definitions would now also be expressions if we were strict about "no statements" which would mean LJ has first-class functions (and potentially lambdas).

function1 = main() { println("Hello, world!" }

function1() // "Hello, world!"
main() // "Hello, world!

function2 = (arg1, arg2) { printf("%s, %s", arg1, arg2) }
function2("cats", "dogs") // "cats, dogs"

function3(otherFunction, arg1, arg2) {
    return otherFunction(arg1, arg2)
} 

function3(function2, "cats", "dogs") // "cats, dogs"

class1 = Dog { ...class stuff... }
dog1 = class1() // Returns a new Dog instance
dog2 = Dog() // Returns a new Dog instance

class2 = { ...class stuff... } // LJ uses '{ }' for sets, so there needs to be some disambiguation here
object1 = class2()

someFactoryFunction(someClass, args) {
    return someClass(args)
}

someFactoryFunction(class1, args) // Returns a new Dog instance

Treating everything like an expression feels more clear. It might seem odd to beginners that some funny words "return" stuff while other funny words "do" stuff. Some beginners have trouble figuring out when to use print() and when to use a return for example.

Lingua principale
Java
Stelle
6
Fork
7
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di JMU-CS/less-java

Tutte le issue di JMU-CS/less-java

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.