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

feature: visualize the go code #25

Open
hitzhangjie opened this issue Jan 6, 2021 · 0 comments
Open

feature: visualize the go code #25

hitzhangjie opened this issue Jan 6, 2021 · 0 comments

Comments

@hitzhangjie
Copy link
Owner

hitzhangjie commented Jan 6, 2021

I am trying on this, it's a little complex, not that so complex. And I am not using plantuml activity.
Displaying the participants, branches, actions all in sequential diagram maybe better to understand.

ballerina sample 1:
image

ballerina sample 2:
image

The picture above is from Ballerina microservice framework. I do some trying for golang.

Before showing some samples, I want to share my thinkings.

  1. which language construct or activities should we visualize?
    I think OOP is good.
    Maybe what we care most is the Participants and Communication.
    Besides, we care the condition branches. like when something happens? If it happens, what we should do?

  2. what communication stands for?

    • method call (method has receiver type): object sends message to another object
    • package exported function call: this maybe not a message passing, but it still looks important for us.
    • RPC or network activity.
    • etc.

    ps: After I do some trying on this, I think it would be better if we could specify which activity we should focus on.

  3. how should we visualize these constructs or activites?

    • plantuml: plantuml is an option, but maybe we should look for better solutions.
      plantuml generates an static picture, sometime it is enough, maybe most time, it's not.
      when we reading code or trying to understand code, what we focus changes as we navigate, a little like the IDE supports code folding feature.
      some syntax like if-else/switch-case/for-loop rendered by plantuml is a little hard to understand, the alt-else/loop is not clear enough.

some samples:

  1. IfStmt
func TestIfElse() {

	num := 1
	if num == 1 {
		fmt.Println("1")
	} else if num == 2 {
		fmt.Println("2")
	} else {
		fmt.Println("others")
	}
}

and relevant puml:

@startuml
participant ifstmt
alt ../../testdata/ast/ifelse.go:8:5
	ifstmt->ifstmt
	note right: stmt ../../testdata/ast/ifelse.go:9:3
else ../../testdata/ast/ifelse.go:10:9
	alt ../../testdata/ast/ifelse.go:10:12
		ifstmt->ifstmt
		note right: stmt ../../testdata/ast/ifelse.go:11:3
	else ../../testdata/ast/ifelse.go:12:9
		ifstmt->ifstmt
		note right: stmt ../../testdata/ast/ifelse.go:13:3
	end
end
@enduml

rendered picture:

image

ForStmt

package ast

import "fmt"

func TestForStmt() {
	for i := 0; i < 10; i++ {
		fmt.Println("hello world")
	}
}

relevant puml:

@startuml
participant forStmt
group ForStmt
	forStmt->forStmt
	note right: init ../../testdata/ast/for.go:6:6
	loop ../../testdata/ast/for.go:6:14
		forStmt->forStmt
		note right: body stmt: ../../testdata/ast/for.go:7:3
		forStmt->forStmt
		note right: post ../../testdata/ast/for.go:6:22
	end
end
@enduml

rendered picture:

image

take a real project as example:

image

Just a little try, It even cannot satisfy my own usage.

If we could find a better reprentation manner, it would be better.
I learned that the microservice framework Ballerina supports graphical editor, https://medium.com/ballerina-techblog/ballerina-vscode-plugin-graphical-editor-for-ballerina-b6af226178d6.

Maybe we could use this render method like Ballerina, though it would be much more complex. Or we could add some options to exclude/include the language constructs.

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

No branches or pull requests

1 participant