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

[Discussion] Ideas for additional normalizations #26

Open
junedev opened this issue Aug 18, 2022 · 1 comment
Open

[Discussion] Ideas for additional normalizations #26

junedev opened this issue Aug 18, 2022 · 1 comment
Labels
x:rep/large Large amount of reputation

Comments

@junedev
Copy link
Member

junedev commented Aug 18, 2022

This issue is to collect ideas for additional normalizations that the representer could make so that more student solutions would get a matching representer comment in the future.

Some things to keep in mind:

  • The admins currently tend towards the idea that it would be ok if the analyzer would comment on something and the representer would then normalize the same thing. So just because something is listed below does not mean the student would not get feedback on it.
  • The mentor that writes a representer comment would see a list of normalizations that are potentially applied and should therefore not be commented on.
  • Some normalizations might not be worth the effort coding them as they will not significantly decrease the number of unique/rare representations. It is a bit hard to tell which ones those are exactly and where to draw the line so it is ok to collect all ideas for now.

The normalizations that are currently applied can be found in the README.

Ideas for additional normalizations:

  • variable declarations, e.g. var a string vs. a := ""
  • variable increment, i++ vs. i = i + 1 vs. i += 1
  • make without capacity and length vs. non make version (slices/maps)
  • new(someStruct) vs. &someStruct{}
  • unnecessary variable declaration before return
    x := someFunction()
    return x
    
  • Single import with and without brackets
    import "fmt"
    // vs.
    import (
        "fmt"
    )
    
  • Named return values but the names are unused
    func myFunc() (y int) {
       return calc()
    }
    
  • Remove example tests that a student might have written
  • len(someString) == 0 vs. someString == ""
  • expressions where the order does not matter, e.g. simple math expressions like return 2*x vs. return x*2
  • constants with unnecessary type definition, e.g. const x int = 40 vs. const x = 40 (not sure it is possible to know when this normalization is ok to do though)
  • slice[0:n] vs. slice[:n]
  • > x-1 vs. >= x when x is int/uint

(Some items on the list are taken over from #10. Note that some others listed there were already implemented. Other items on the list are from looking at distinctions that appear between the current representations.)

If you have additional ideas or are interested in implementing one of the normalizations, please leave a comment below.

@junedev junedev pinned this issue Aug 18, 2022
@junedev junedev added the x:rep/large Large amount of reputation label Aug 18, 2022
@tehsphinx
Copy link
Member

Have a first version to normalize

  • variable declarations, e.g. var a string vs. a := ""

Need to test it with different cases and will make a PR after 🙂

I'm using the assignment as the normalization so we can cover more cases with less representers:

var a string
// -> (representer normalization)
a := ""

var a string = "abc
// ->
a := "abc"

var a = "abc
// ->
a := "abc"

var (
    a string
    b int
)
// ->
a := ""
b := 0

var a, b string
// ->
a := ""
b := ""

var (
    a string
    b, c int
)
// ->
a := ""
b := 0
c := 0

var (
    a = "abc"
    b, c = 1, "cde"
)
// ->
a := "abc"
b := 1
c := "cde"

var a, b = "abc", "cde"
// ->
a := "abc"
b := "cde"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
x:rep/large Large amount of reputation
Projects
None yet
Development

No branches or pull requests

2 participants