Skip to content

Preferred dREL coding style? #21

@rowlesmr

Description

@rowlesmr

Is there a preferred style for writing dREL? In my head, I'm thinking a mashup of Python ('cause no tabs in CIFs) and C++ ('cause {})

A few different ways of writing the same thing. The first example is self-consistent, the second has a few things going on.

With a as atom_site_aniso
    # indent here, as now we're inside a 'With' block
    If(a.ADP_type == 'betaani')  # no spaces here apart from around operators
    {                            # opening brace on newline
        #indent one level inside a new block
        a.matrix_beta = [[a.beta_11, a.beta_12, a.beta_13],  # no spaces between
                         [a.beta_12, a.beta_22, a.beta_23],  # '[' and next
                         [a.beta_13, a.beta_23, a.beta_33]]  # token           
    }
    Else If(a.ADP_type == 'Bani')  # 'Else If' go together on one line
    {
        UIJ = b.matrix_B / (8 * Pi**2)
    }
    Else 
    {
        CUB = _cell.convert_Uij_to_betaij
        a.matrix_beta =  CUB * UIJ * CUB  # use the 'With' abbreviation in the
                                          # assignment of the value to the dataname
                                          # that is the subject of the dREL
    }                                                                              

##############################################################################    
    
With a as atom_site_aniso
# no extra indent, as 'With' is "just" a typedef
If ( a.ADP_type == 'betaani' ) {  # spaces everywhere. opening { on this line
    a.matrix_beta = [ [ a.beta_11, a.beta_12, a.beta_13 ],  # spaces between
                      [ a.beta_12, a.beta_22, a.beta_23 ],  # '[' and next
                      [ a.beta_13, a.beta_23, a.beta_33 ] ] # token           
}
Else If ( a.ADP_type == 'Bani' )  # No {} with a single statement If block
    UIJ = b.matrix_B / (8 * Pi**2)
Else {
    CUB = _cell.convert_Uij_to_betaij
    _atom_site_aniso.matrix_beta =  CUB * UIJ * CUB # use the full dataname in the
                                                    # assignment of the value to the dataname
                                                    # that is the subject of the dREL                                       
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions