Feedback on Assignment 1: BDDs

  1. Set your git name and email correctly

    berkayc, denizarberk, francesca.albio, juliaoli, anasistac,
    cosimo-radler, TomUng, Petra.Kocsis, zsofia.sandor, MariaGeorgescu
    ssouppeyy, Māra, mara, Ytse, juliedeboer,
    mayairemozbayoglu, MafaldaCandal, han, memet
    Barbara_Plebanowicz
    
  2. Use one single git name and email

    5  Ana Sistac Plaza
    2  Ana Sistac
    1  anasistac
    
    6  Leon Wloch
    1  Leonard Wloch
    
    melledoucet@sp-byods-145-109-3-187.wireless.uva.nl
    melledoucet@sp-byods-145-109-7-102.wireless.uva.nl
    melledoucet@Melles-MacBook-Pro-2.local
    
    elifkozan@sp-byods-145-109-15-177.wireless.uva.nl
    elifkozan@sp-byods-145-109-16-90.wireless.uva.nl
    
    leticiadupleich@sp-byods-145-109-28-214.wireless.uva.nl
    leticiadupleich@MacBook-Pro-de-admin.local
    
    jonathancowley@Jonathans-MacBook-Air.local
    jonathancowley@sp-byods-145-109-37-160.wireless.uva.nl
    jonathancowley@sp-byods-145-109-33-249.wireless.uva.nl
    
  3. Make your scripts executable

    chmod +x simplify_truth_table.py
    
  4. Don't copy, import. "read_truth_table function is copied to this file from simplify_truth_table.py"
  5. I'm not a fan of end-of-line comments. Better put them on the line before. Otherwise things can get very cluttered. In any case it's often better to write your code so that it speaks for itself and doesn't need the comment.

    if len(line) > 5:  # Makes sure we don't get parse the None line
        pass
    
    # Makes sure we don't get parse the None line
    if len(line) > 5:
        pass
    
  6. Comprehension

    def combine_terms(term1, term2):
        combined = []
        for a, b in zip(term1, term2):
            if a == b:
                combined.append(a)
            else:
                combined.append(None)
        return combined
    
    
    def combine_terms(term1, term2):
        return [a if a == b else None for a, b in zip(term1, term2)]
    
  7. Refactor where possible

    def read_and_print_truth_table():
        """Reads a truth table from a file and prints it."""
        with open("truth_table.txt", "r") as f:
            lines = f.readlines()
        for line in lines:
            print(line, end="")
    
    def read_and_print_truth_table():
        """Reads a truth table from a file and prints it."""
        with open("truth_table.txt", "r") as f:
            for line in f.readlines():
                print(line, end="")
    
  8. Only import what you need

    import numpy as np
    
  9. Limit lines to < 80 chars. Also comments.
  10. When you read a line and then write it, Python keeps the newline at the end of the line it read and also adds a newline after printing it. That might not be what you want.

    with open("file.txt") as inf:
        for line in inf.readlines():
            print(line)
    
    with open("file.txt") as inf:
        for line in inf.readlines():
            print(line[:-1])
    
    with open("file.txt") as inf:
        for line in inf.readlines():
            print(line, end="")
    
  11. Python functions should use snake case, not PascalCase, i.el get_val, not GetVal
  12. Let the names of variables say a little more about what they carry. Not just term1, term2, new_term. With better names your code can become "self-documenting"
  13. Do not print excessive output. It makes it more difficult to pipe

    $ python ./decision_table.py  | python ./optimize_truth_table_bdd.py
    Not(Or(And(a, ~b), And(a, c)))
    This is the best variable ordering resulting in the smallest bdd ['a', 'b', 'c']
    
  14. Commit message: "Jill on Jack's laptop" Commit your own work under your own name. (Group grades and individual grades.)
  15. Learn how to make long commit messages with Emacs, vim, or whatever code editor you use.
  16. Recommendations for Git Commit Messages
  17. Use docstrings, not this

    ########################################################
    ## Function to order the BDD based on the given order ##
    ########################################################
    def order_bdd(expression, order):
    
  18. Be careful of superfluous whitespace in your code files. It can mess up your git diffs.
  19. Write information-carrying commit messages.

    a412 * Update optimize_truth_table.py
    246b * Update optimize_truth_table.py
    c9c2 * Update optimizing_truth_table.py
    593f * Update simplify_truth_table.py
    e71b * Update optimizing_truth_table.py
    e177 * Update not_working_pyeda_version.py
    9a96 * Update optimizing_truth_table.py
    7092 * Update optimizing_without_pyeda.py
    6621 * Update optimizing_without_pyeda.py
    4883 * Update optimizing_without_pyeda.py
    1c97 * Update optimizing_without_pyeda.py
    

    git_commit_2x.png

Author: Breanndán Ó Nualláin <o@uva.nl>

Date: 2025-03-24 Mon 15:24