Change generator to stop translating colon to underscore
Closed this issue · 1 comments
Currently the generator translates the colon in an objective-c method into an underscore. This leads to the undesirable result of methods with names that end with an underscore (e.g. ObjectForKey_() instead of ObjectForKey() ). I suggest that these rules be implemented when generating Go function names:
-
For class methods we use the format Classname_methodname(). There are times when the method name is shorted, like when the last part of the class name contains the first part the method name (e.g. NSArray_WithObjects() instead of NSArray_arrayWithObjects() ). I do agree with that format but I still think it is a good idea to also include a method that includes the full method name. It is a lot less confusing for new people. Of course the shorted method could lead to confusion as to which objective-c method it wraps, so maybe be should remove all these shorten methods and replace them with more proper names.
-
Instance methods should use the Go format of using uppercase for the first letter of each word. I don't think we need underscores at all. For example instead of the NSUserDefaults' method SetObject_ForKey() it should be SetObjectForKey(). It looks more Go-like (and pretty 😁).
I created this patch to translate underscores into nothing. I haven't had the best of luck with Macschema so I need help with testing it out. If anyone could let me know if this patch works, it would be appreciated.
From 7f0c08628ede2b3d7370387004bff366459c925b Mon Sep 17 00:00:00 2001
From: programmingkidx@gmail.com
Date: Tue, 4 Jul 2023 17:50:30 -0400
Subject: [PATCH] Generator Go method names without any underscore characters.
---
gen/gen.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gen/gen.go b/gen/gen.go
index 61b5b30..00479f9 100644
--- a/gen/gen.go
+++ b/gen/gen.go
@@ -29,7 +29,7 @@ func msgSendFuncName(cls schema.Class, selector string, isTypeMethod bool) strin
}
func selectorNameToGoIdent(sel string) string {
- return strings.ReplaceAll(sel, ":", "_")
+ return strings.ReplaceAll(sel, ":", "")
}
// Objective-C properties are syntactic sugar for getter/setter methods, this
--
2.36.1
0001-Generator-Go-method-names-without-any-underscore-cha.patch