<p>I'm new in go and I am having problems at writing objects (maybe because of the different syntax). Then I realize wouldnt it be easier to make a command line tool that takes code in a syntax similar to Java or other OO langauge and convert into go code. </p>
<p>I made some research on how it would work and I think a precompiler similar to Sass/Scss would work.</p>
<p>What do you guys think? Is it a good idea?</p>
<hr/>**评论:**<br/><br/>mistretzu: <pre><p>it's not a good idea.. it takes more time to write that tool than to learn Go syntax which is quite easy and predictable.. </p></pre>NotWhisperer: <pre><p>I see. Now that I think about, if I had spend as much time researching about the Go syntax than researching this, I would already have good grasp of the syntax. Too much coffee I guess.</p></pre>drvd: <pre><blockquote>
<p>Is it a good idea?</p>
</blockquote>
<p>No. This is a very bad idea.</p></pre>cafxx1985: <pre><p>And this is a really bad answer.</p>
<p>(by not giving any rationale for it you're being dogmatic and condescending -- and this is particularly bad since OP is clearly a beginner)</p></pre>kor_the_fiend: <pre><p>Spend your time learning and practicing the syntax. Once you've mastered it, you'll be glad you did. It's a really expressive and readable syntax and I now prefer it over more traditional c-style formatting.</p></pre>Loves_Portishead: <pre><p>For code generation there is `<code>//go:generate</code> already, if you look into the tools like <code>gofmt</code> there is already code for manipulating the ASTs/etc.</p>
<p>If you look into tooling such as <code>grpc</code> you will see that generating stubs from simplified representations <em>in order to speed up the initial development</em> is already a common paradigm.</p>
<p><strong>Edit:</strong> Down-votes for answering a beginners question? Are we so insecure that we don't even want to give someone the tools to look at solving their own problems? Nobody says you have to use whatever he may come up with.</p></pre>TheRealMrTux: <pre><p>I wouldn't say, this is a bad idea in general. It might not be useful to anyone (including yourself), but might be a great little project to learn something about go and precompilers. Just take it as an exercise.</p></pre>PaluMacil: <pre><p>I don't think you should use it, but I do think writing compilers, parsers, etc is a very good academic challenge, and writing one would probably be a fun experience. By the time you're done, you'll know the Go way to do things. ;) @Loves_Portishead mentioned go generate, and that could be a way to call your tool.</p></pre>shovelpost: <pre><p>Take a step back and try to read the Go code and say out loud what you read. You'll find that it reads much better than most other languages.</p>
<p>For example:</p>
<pre><code>var s string // A variable s of type string
var string s // Variable string s?
</code></pre>
<p>Try this with more complex code too.</p>
<p>Once you realize how great it is, you might even have a hard time going back.</p></pre>