Skip to content

Refactor: rename methods/attrs/locals to follow Python conventions #58

Description

@dbqpdb

A focused rename pass to bring the codebase in line with Python naming conventions. Distinct from #45 (PEP 8 layout / whitespace / line length) — this issue is specifically about what things are named, while #45 is about how the code is formatted. There is some overlap on case style (camelCase → snake_case).

Scheduling note: this work is deferred until the following rlm.py-touching PRs land, to avoid heavy rebases:

Once those merge, this should be doable as one focused PR.

Scope

Four categories:

  1. camelCase / mixedCase → snake_case for methods, attributes, and locals (PEP 8 for callables).
  2. Privacy conventions — single underscore prefix (_foo) for methods and attributes that are clearly internal helpers.
  3. Class-name cleanupKQRBN_Piece has an underscore; PEP 8 says CapWords with no underscores.
  4. Factory-method naming convention — classmethods that construct an instance should use the from_X form (e.g. Board.from_fen).

Concrete renames

Public method names (snake_case)

Current Proposed
Board.isValidFENboard Board.is_valid_fen_board
Board.is_FEN Board.is_fen
Board.to_FEN_board Board.to_fen_board
Board.convert_FEN_to_board_array Board.fen_to_array (classmethod returning np.ndarray — not a Board factory, so not from_fen)
Board.squareIdx_to_boardIdxs Board.square_idx_to_board_idxs

Privacy renames (only-called-internally → _-prefixed)

Currently public but only called from within their own class:

Current Proposed
KQRBN_Piece.get_single_move KQRBN_Piece._single_move
KQRBN_Piece.get_ray_moves KQRBN_Piece._ray_moves
King.get_kingside_castle_move King._kingside_castle_move
King.get_queenside_castle_move King._queenside_castle_move
King.get_castling_allowed_by_position King._castling_allowed_by_position
King.get_castling_allowed_by_check King._castling_allowed_by_check

If any of these turn out to have external callers we haven't identified, that's a sign the privacy choice was wrong and they should stay public.

Class name

Current Proposed
KQRBN_Piece KQRBNPiece (or NonPawnPiece if we prefer descriptive over abbreviated — open to discussion)

Local variable names (camelCase → snake_case)

Mostly in Board.convert_FEN_to_board_array and Board.squareIdx_to_boardIdxs:

Current Proposed
squareIdx square_idx
fileIdx file_idx
rankIdx rank_idx
FEN_board, FEN_chars fen_board, fen_chars
K_str (in find_king_square) king_char

Already correct — no change needed

Method-role tagging (@classmethod vs @staticmethod vs instance)

The current classmethod vs instance method split is mostly sensible. Two minor calls worth considering during the pass:

  • Move.square_to_string(cls, sq) uses cls.IDX_TO_FILE_DICT. Could be @staticmethod if we hoisted IDX_TO_FILE_DICT out of the class, but cleaner as-is.
  • Board.square_rank_str, Board.square_file_lett: similar — use Board.IDX_TO_FILE_DICT, fine as classmethods.

Reviewer judgement at the time, but defaulting to "leave as-is unless there's a reason."

Test plan

Out of scope

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions