After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 688447 - Generated C code could prettier
Generated C code could prettier
Status: RESOLVED OBSOLETE
Product: vala
Classification: Core
Component: Code Generator
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on: 593559 614788 615305 622708 702602 734953 769935 772661
Blocks:
 
 
Reported: 2012-11-16 10:15 UTC by Murray Cumming
Modified: 2018-05-22 14:36 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
ccode: Reformat function declaration and definition for better readability (2.08 KB, patch)
2017-04-25 09:22 UTC, Rico Tzschichholz
committed Details | Review

Description Murray Cumming 2012-11-16 10:15:29 UTC
Some thought about the generated code that seem fixable. This would make people feel better about knowing that they can switch to the C code one day, and make it easier to debug problems in the generated code.

1.
It would be nice if functions were laid out like in glib/gtk+ code:
  static ReturnType
  function_name()

rather than
  static ReturnType function_name()

2.
There should be newlines between things such as functions, defines and enums. Right now it is all bunched up together like this:

void module_init (RygelPluginLoader* loader);
#define RYGEL_EXAMPLE_SERVER_PLUGIN_NAME "ExampleServerPluginC"
RygelExampleServerPlugin* rygel_example_server_plugin_new (void);
RygelExampleServerPlugin* rygel_example_server_plugin_construct (GType object_type);
GType rygel_example_server_plugin_get_type (void) G_GNUC_CONST;
enum  {
  RYGEL_EXAMPLE_SERVER_PLUGIN_DUMMY_PROPERTY
};
#define RYGEL_EXAMPLE_SERVER_PLUGIN_TITLE "Example Server Plugin C"
#define RYGEL_EXAMPLE_SERVER_PLUGIN_DESCRIPTION "An example Rygel server plugin implemented in vala."
RygelExampleRootContainer* rygel_example_root_container_new (const gchar* title);
RygelExampleRootContainer* rygel_example_root_container_construct (GType object_type, const gchar* title);
GType rygel_example_root_container_get_type (void) G_GNUC_CONST;

3.
Pointer type syntax could be like glib/GTK+. I don't like it (I like C++) but it's normal for C:

For instance, now I have:

  RygelExampleServerPlugin * self = NULL;
  RygelExampleRootContainer* _tmp0_;

(Notice the extra space on that first line).
though this would be more normal:

  RygelExampleServerPlugin *self = NULL;
  RygelExampleRootContainer *_tmp0_;

4.
There should be newlines between if() blocks and the following code.

5.
There should be newlines between the initial variable declarations and the g_return_if*() checks, and then between those checks and the actual code.

6.
This is harder to do right, but it would be nice if the lines were split, with an indent, at 80 (or so) columns.
Comment 1 Murray Cumming 2012-11-16 10:20:54 UTC
Also, many of these tmp variables seem to be unnecessary, obscuring the code.
Comment 2 Murray Cumming 2012-11-19 10:18:43 UTC
Some more points:

It would be nice if it used G_DEFINE_TYPE() and similar when possible.

I also find these *_construct() methods strange. They mean that objects cannot be instantiated with just a simple g_object_new() call and derived classes must call the _construct() function of the base class.
Comment 3 Al Thomas 2016-11-11 20:25:39 UTC
There are too many points here to make this a single fixable bug, but it serves as a useful heading for bugs relating to the C code writer. Adding dependent bugs allows for developers looking to improve Vala's ability to write C to a high standard to find relevant items to work on.
Comment 4 Rico Tzschichholz 2017-04-25 09:22:10 UTC
Created attachment 350382 [details] [review]
ccode: Reformat function declaration and definition for better readability
Comment 5 Rico Tzschichholz 2017-11-19 14:03:43 UTC
Comment on attachment 350382 [details] [review]
ccode: Reformat function declaration and definition for better readability

Attachment 350382 [details] pushed as 3019b67 - ccode: Reformat function declaration and definition for better readability
Comment 6 Al Thomas 2017-12-05 18:58:06 UTC
For reference there is a GNOME C coding style guide:
https://developer.gnome.org/programming-guidelines/stable/c-coding-style.html.en
Comment 7 GNOME Infrastructure Team 2018-05-22 14:36:40 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/vala/issues/336.