Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update doc domain-modeling-tools for Java method call without parentheses #3081

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cuzfrog
Copy link

@cuzfrog cuzfrog commented Oct 3, 2024

Add parentheses when calling LocalDate.now to get an instance of LocalDate.

For a parameterless method, the recommended convention is that if no side effects, it should be without parentheses, so that def can be replaced by val/var.

In Scala3, the call site is enforced to match the method definition:

scala> def foo = 1
def foo: Int
scala> def bar() = 1
def bar(): Int    
scala> foo
val res3: Int = 1                  
scala> bar
-- [E100] Syntax Error

But this is not true when citing Java method:

scala> import java.time.*              
scala> val f = LocalDate.now // Questionable, side effect (reading external value)
val f: java.time.LocalDate = 2024-10-03                
scala> val t = LocalDate.now() // Good, explicitly mark the side effect performed
val t: java.time.LocalDate = 2024-10-03                  
scala> val f: () => LocalDate = LocalDate.now
val f: () => java.time.LocalDate = Lambda/0x000076984050d000@6c9151c1

This PR is to make the doc example follow the convention strictly.

Add parentheses when calling `LocalDate.now` to get an instance of `LocalDate`.
Copy link
Member

@bishabosha bishabosha left a comment

Choose a reason for hiding this comment

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

Thanks, but maybe we can avoid any style debates by using the of factory

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