Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in
  • E escet
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 84
    • Issues 84
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 4
    • Merge requests 4
  • Deployments
    • Deployments
    • Releases
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • Eclipse Projects
  • Eclipse ESCET (Supervisory Control Engineering Toolkit)
  • escet
  • Issues
  • #194

Closed
Open
Created Sep 29, 2021 by Dennis Hendriks@ddennisMaintainer

Reconsider requiring curly braces for single-statement if-bodies

From https://www.eclipse.org/lists/escet-dev/msg00182.html:

I still don't like the "single statement needs curly brackets" thing. It makes handling a trivial case costing 3 lines, and if you have a bunch of such lines, it explodes in length.

   public Node conjunct(Node a, Node b) {
       if (a == b) return a;
       if (a == Tree.ZERO || b == Tree.ZERO) return Tree.ZERO;
       if (a == Tree.ONE) return b;
       if (b == Tree.ONE) return a;

   public Node conjunct(Node a, Node b) {
       if (a == b) {
           return a;
       }
       if (a == Tree.ZERO || b == Tree.ZERO) {
           return Tree.ZERO;
       }
       if (a == Tree.ONE) {
           return b;
       }
       if (b == Tree.ONE) {
           return a;
       }

I don't know about you, but I find the first version much easier to globally grasp there are 4 if statements. If there is an empty line below it, it trivially makes a group of code. >The bottom version takes effort to understand, at least I need to search for the start of the next statement. Conditions and actions are mixed vertically.

Assignee
Assign to
Time tracking

Copyright © Eclipse Foundation, Inc. All Rights Reserved.     Privacy Policy | Terms of Use | Copyright Agent