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

Refactor of the code base: Remove underscore functions and refactor a panic #59

Merged
merged 5 commits into from
Aug 29, 2022

Conversation

Skarlso
Copy link
Contributor

@Skarlso Skarlso commented Aug 16, 2022

What this PR does / why we need it:

Cleanup and replacing panics and error handling.

This is branched off from #57. I'll rebase once that's merged.

Which issue(s) this PR fixes:
Related to #52. This doesn't close it yet.

I also removed the test package. It shouldn't be living with the codebase.

Special notes for your reviewer:

Release note:

@Skarlso Skarlso requested a review from a team as a code owner August 16, 2022 15:22
@Skarlso Skarlso requested review from robertgraeff and enrico-kaack-comp and removed request for a team August 16, 2022 15:22
@gardener-robot
Copy link
Contributor

@Skarlso Thank you for your contribution.

@Skarlso Skarlso changed the title Slowly remove panics from the codebase and clean up some left over and unused files [WIP] Slowly remove panics from the codebase and clean up some left over and unused files Aug 16, 2022
@Skarlso Skarlso requested a review from yitsushi August 17, 2022 09:52
@Skarlso Skarlso changed the title [WIP] Slowly remove panics from the codebase and clean up some left over and unused files [WIP] Slowly remove panics from the codebase Aug 17, 2022
@Skarlso Skarlso requested a review from mandelsoft August 17, 2022 12:16
Copy link
Contributor

@yitsushi yitsushi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AddKnownTypes() is in the repo, but in a different package, so technically it's en external call.

cmds/ocm/commands/ocmcmds/common/inputs/inputtype.go Outdated Show resolved Hide resolved
pkg/contexts/config/core/configtypes.go Outdated Show resolved Hide resolved
pkg/contexts/credentials/core/repotypes.go Outdated Show resolved Hide resolved
pkg/contexts/oci/core/repotypes.go Outdated Show resolved Hide resolved
pkg/contexts/ocm/core/repotypes.go Outdated Show resolved Hide resolved
@Skarlso Skarlso changed the title [WIP] Slowly remove panics from the codebase remove panics from the codebase: part 1 Aug 19, 2022
Comment on lines 57 to 60
func (t *configTypeScheme) AddKnowntypes(s ConfigTypeScheme) {
t.Scheme.AddKnownTypes(s)
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have you removed this. It is a useful interface function, even if it is not yet used.
It assures correct typing by overriding the inherited function and accepting the correct sub type.
And it therefore avoids the occurrence of a potential error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not following. This function is a lowerCase AddKnownTypes for some reason. It was never called from anything. Not even using reflection I did a search for the string. :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. It is intended for a library user who does not want do deal with errors. Because of its parameter type, calling the base method cannot cause an error. It assures the correct element type. And the only error reason cannot appear, so the errors code can be ignored.

Because Go does not support method overloading by parameter types, I had to choose another method type.

May be with Generics this will be better, but so far the lib is without generic, and I still would prefer to keep it this way.
There are so many places where Generics could simplify the code, but it would be a real redesign.

Basically I already tried some more complicated cases, but the Go generics solution failed to handle them correctly. There are two important things missing: upper AND lower bound operator, and a much better type inference.

pkg/env/env.go Outdated
Comment on lines 48 to 66
type fsOpt struct {
dummyOption
path string
fs vfs.FileSystem
}

func FileSystem(fs vfs.FileSystem, path string) fsOpt {
return fsOpt{
path: path,
fs: fs,
}
}

func (o fsOpt) Mount(cfs *composefs.ComposedFileSystem) error {
return cfs.Mount(o.path, o.fs)
}

////////////////////////////////////////////////////////////////////////////////

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a valid interface function of the lib.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Completely unused by anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's why I removed it. It clutters the code base. Unless there is some reference somewhere to this?

It is in version control, so once we DO need for something, we can always just add it back in. :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is intended as a library, Therefore is natural, that not all methods/functions are already used. The included CLI code is just one client of the lib, but not necessarily the only one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, if it is intended to be used as a library, this should be made clear that this is an open option. Either through documentation or through other means, such as usage or packaging that surfaces this.

But that's a different problem. I can put this back in. :)

"tree": get_tree,
var outputs = output.NewOutputs(getRegular, output.Outputs{
"wide": getWide,
"tree": getTree,
}).AddChainedManifestOutputs(OutputChainFunction())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you urgently want to change this, it should be changed everywhere. There are several commands following this pattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I change these as I encounter them. This PR is not concerned with that. However, I can open a separate PR just with naming refactors. :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that seems to be better. I tried to keep the codebase somehow consistent. So if we change these method names (no problem with that :-) ). we should change it in all commands, because these methods have the same meaning and name in all those commands.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will do that ( open a separate PR ).

cmds/ocm/commands/ocmcmds/common/inputs/inputtype.go Outdated Show resolved Hide resolved
cmds/ocm/commands/ocmcmds/common/inputs/inputtype.go Outdated Show resolved Hide resolved
@Skarlso Skarlso requested a review from mandelsoft August 29, 2022 07:47
"tree": get_tree,
var outputs = output.NewOutputs(getRegular, output.Outputs{
"wide": getWide,
"tree": getTree,
}).AddChainedManifestOutputs(OutputChainFunction())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that seems to be better. I tried to keep the codebase somehow consistent. So if we change these method names (no problem with that :-) ). we should change it in all commands, because these methods have the same meaning and name in all those commands.

Comment on lines 57 to 60
func (t *configTypeScheme) AddKnowntypes(s ConfigTypeScheme) {
t.Scheme.AddKnownTypes(s)
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. It is intended for a library user who does not want do deal with errors. Because of its parameter type, calling the base method cannot cause an error. It assures the correct element type. And the only error reason cannot appear, so the errors code can be ignored.

Because Go does not support method overloading by parameter types, I had to choose another method type.

May be with Generics this will be better, but so far the lib is without generic, and I still would prefer to keep it this way.
There are so many places where Generics could simplify the code, but it would be a real redesign.

Basically I already tried some more complicated cases, but the Go generics solution failed to handle them correctly. There are two important things missing: upper AND lower bound operator, and a much better type inference.

pkg/contexts/config/core/configtypes.go Show resolved Hide resolved
pkg/env/env.go Outdated
Comment on lines 48 to 66
type fsOpt struct {
dummyOption
path string
fs vfs.FileSystem
}

func FileSystem(fs vfs.FileSystem, path string) fsOpt {
return fsOpt{
path: path,
fs: fs,
}
}

func (o fsOpt) Mount(cfs *composefs.ComposedFileSystem) error {
return cfs.Mount(o.path, o.fs)
}

////////////////////////////////////////////////////////////////////////////////

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is intended as a library, Therefore is natural, that not all methods/functions are already used. The included CLI code is just one client of the lib, but not necessarily the only one.

@gardener-robot gardener-robot added size/xl and removed size/m Medium labels Aug 29, 2022
@Skarlso Skarlso changed the title remove panics from the codebase: part 1 Refactor of the code base: Remove underscore functions and refactor a panic Aug 29, 2022
@@ -1,295 +0,0 @@
// Copyright 2022 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mandelsoft Let's remove this if you don't mind, it's completely commented out.

func process(op operation) processing {
return func(it data.Iterable) data.Iterable {
slice := []interface{}{}
var slice []interface{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure the using code works with a nil array, because this is the difference you produce with this change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted this.

@mandelsoft mandelsoft self-requested a review August 29, 2022 13:07
@Skarlso Skarlso merged this pull request into main Aug 29, 2022
@Skarlso Skarlso deleted the remove-panics branch August 29, 2022 13:09
@mandelsoft mandelsoft mentioned this pull request Aug 30, 2022
mandelsoft added a commit that referenced this pull request Aug 30, 2022
* Deleted a bunch of things which significantly sped up build time

* Apply suggestions from code review

Co-authored-by: Balazs Nadasdi <[email protected]>

* Updated error message and added expected type information

* Putting back the removed stuff

* Renaming funcs with underscore in it.

Co-authored-by: Gergely Brautigam <[email protected]>
Co-authored-by: Balazs Nadasdi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants