A GUI port of the framework from Python to Go. Analysis of rakes and buns

With Python I had to work out of hopelessness - ML, neural networks, scripting, so it was more handy on it. But time goes by and anxiety about the speed of your code pushes you to something faster and more reliable.





The task of porting the GUI framework was painful, because my universal Unigui worked only from Python and was universal only in theory. An extremely laconic API was developed in it, which should have been preserved in the Go version. In addition, the mass of automatism for generating the necessary data was not subject to porting, since Go lacks compilation order control, preprocessor, metaprogramming, which guaranteed a tricky Spartan experience.





The first difficulty I got into was the impossibility of directly assigning promouted (nested) fields in and only in the struct initializer. If the structure has an unnamed nested structure, then its fields can be accessed from the outer root everywhere, except for the initializer. Because of what, among other things, the whole idea with nested fields as with replacing the hierarchy has become both dubious and cumbersome to use. To require the user to write long nested initializers with unnecessary types would be the height of indecency. All GUI structures have become completely flat, independent, although there is a clear hierarchy in Python.





The verbiage that Go demanded when assembling objects still remained. The user of the library needs a short, understandable call, but here I have to make him remember the fields of the object and use in the initializer and somehow indicate that some must be filled in, and the default parameters are not, as it turned out, "a consequence of poor API design" ... Golden words, as usual, do not correlate with reality. It was decided to hide this from the eyes and give the user a set of helpers with the same names that the types should have, which will do all the tedious work and immediately return a pointer. That the user can easily forget the helper will do it himself. Object types now look like Type_ and the Type (...) helper returns * Type_. In fact, these are constructors from OOP to hide the gut of Go code that are unsightly for me and the user.





Go Json . nil ( ), nil nil a / [ ] . , β€” . k, Google, , == nil, = make(0, []Any). , == nil, reflect != nil. reflect.ValueOf(ptr).IsNil() , , true! , ..





hash. . . . . .





, ? , , Any β€” interface{}. ! ,  100% β€” . β€œ , !” 





. , , ( ) , , . , , . , ( ). Google





 MyField int json:"myfield"



, JSON . β€” - . ? , , β€” , , . .. !





  Dart _ . , Go Dart- , . . .  , Google , β€œβ€ . , , , , ?





, map/filter/.. , RemoveAtIndex, , 1.17 , , , .





? ! fmt.Sprintf. - β€” , , β€” β€œ ”.





  .





  • β€” . , . , , ML- Go… 





  • /. , , Python-a Go β€” . β€” , , , . Python - .





  • / β€” Go. github ( ), . , Visual C++ ~20 , Edit & Continue . , Edit & Continue Go VS Code , , . --. ..





  • . . Go. , . , , , β€” . 





  • . , Go , 20% . 70% reflect . . , . . 





  • . ( 8000 ) Python Go.





Go:





package main
import . "github.com/Claus1/unigui-go"		

func screenTest(user* User)* Screen_{	
	table := Table("Videos",0, nil, []string{"Video", "Duration",  "Links", "Mine"},
	SeqSeq(Seq("opt_sync1_3_0.mp4", "30 seconds",  "@Refer to signal1", true),
		Seq("opt_sync1_3_0.mp4", "37 seconds",  "@Refer to signal8", false)))
			
	cleanButton := Button("Clean table", nil, "")
	selector := Select("Select", "All", nil, []string{"All","Based","Group"})
	block := Block("X Block", Seq(cleanButton, selector), table)
	block.Icon = "api"
	return Screen(block)	
}
func main(){			
	//register screens
	Register(screenTest, "Main", 0, "insights")	
	Start()
}
      
      



Python:





from unigui import *
name = "Main" #name of screen to show
icon = 'blur_linear' #MD icon of screen to show
order = 0 #order in the program menu
table = Table('Videos', 0, headers = ['Video', 'Duration',  'Links', 'Mine'],rows = [
    ['opt_sync1_3_0.mp4', '30 seconds',  '@Refer to signal1', True],
    ['opt_sync1_3_0.mp4', '37 seconds',  '@Refer to signal8', False]    
])
block = Block('X Block',
    [           
        Button('Clean table'),
        Select('Select', value='All', options=['All','Based','Group'])
    ], table, icon = 'api')
blocks = [block] #what to show on the screen
start('Test app')

      
      



Will I continue to use Go? Where am I going to get off the submarine .. and I really want Crystal, Nim, and other simple, advanced languages ​​to break into production and give Go a pendulum. So far, unfortunately, I do not see an alternative to it in the niche of light production for developing productive software. Peace!





Links for the curious:





β†’ Go 





β†’ Python 








All Articles