nautilus/docs/style-guide.html

138 lines
5.1 KiB
HTML
Raw Normal View History

2000-02-15 20:55:05 +00:00
<html>
<head>
<title>Nautilus Coding Style Guide</title>
</head>
<body>
<p>To make code written for Nautilus look and act in a predictable way,
we follow a set of guidelines that specify some details of how we write code.
To start, we follow all the guidelines outlined in the
2000-03-25 02:38:49 +00:00
<a href="http://developer.gnome.org/doc/guides/programming-guidelines/">GNOME Programming Guidelines</a>.</p>
<p>This document covers both things that are not mentioned in the GNOME
Programming Guidelines and things that are mentioned there but need
to be re-emphasized because people don't follow them often enough.</p>
2000-02-15 20:55:05 +00:00
<p>I'm just getting started on this document. Feedback is welcome.
Eventually I'd like better organization and tons of examples.</p>
<blockquote>
<p>- <a href="mailto:darin@bentspoon.com">Darin</a></p>
2000-02-15 20:55:05 +00:00
</blockquote>
2000-03-25 02:38:49 +00:00
<hr>
Some of the underlying work to prepare for emblems on the icons. * style-guide.html: Some minor updates to the style guide, including rules about headers. * libnautilus/nautilus-icon-factory.h, libnautilus/nautilus-icon-factory.c: (nautilus_icon_factory_get_emblem_icons_for_file), (nautilus_scalable_icon_get), (nautilus_icon_factor_clear), (nautilus_icon_factory_load_file), (nautilus_gdk_pixbuf_composite_corner), (nautilus_icon_factor_load_icon), (nautilus_scalable_icon_hash), (nautilus_scalable_icon_equal), (nautilus_icon_factory_get_icon_for_file), (load_specific_image): Added interface for getting emblem icons for a file, and got rid of the symbolic-link overlay that was previously built into the icon. * libnautilus/gnome-icon-container.c (update_icon): Get pixbufs for all emblems and pass into the icon object. * libnautilus/nautilus-icons-controller.c (nautius_icons_controller_get_icon_image): src/file-manager/fm-icons-controller.h, src/file-manager/fm-icons-controller.c (fm_icons_controller_get_icon_image): Return a list of emblem images along with the main image. * libnautilus/nautilus-icons-view-icon-item.h, libnautilus/nautilus-icons-view-icon-item.c (nautilus_icons_view_icon_item_set_emblems), (nautilus_icons_view_icon_item_destroy): Keep a list of emblem pixbufs in each icon. We don't draw them quite yet. * libnautilus/gdk-extensions.h, libnautilus/gdk-extensions.c: (nautilus_gdk_pixbuf_list_ref), (nautilus_gdk_pixbuf_list_unref), (nautilus_gdk_pixbuf_list_free): Convenience functions for manipulating lists of GdkPixbuf objects. * libnautilus/nautilus-directory.h, libnautilus/nautilus-directory.c: (nautilus_file_list_ref), (nautilus_file_list_unref), (nautilus_file_list_free): Convenience functions for manipulating lists of NautilusFile objects. Also got rid of NautilusFileList typedef. * libnautilus/nautilus-icon-factory.h, libnautilus/nautilus-icon-factory.h: (nautilus_scalable_icon_list_free): Convenience function for manipulating lists of NautilusScalableIcon objects. * libnautilus/nautilus-glib-extensions.h, libnautilus/nautilus-glib-extensions.c: (nautilus_g_list_equal): Function to compare two GLists to see if they are identical. Particularly useful with lists of reference-counted objects. * src/file-manager/fm-directory-view-icons.c (fm_directory_view_icons_destroy), (add_icon_if_already_positioned), (fm_directory_view_icons_append_selection_context_menu_items), (display_icons_not_already_positioned), (fm_direectory_view_icons_get_selection): src/file-manager/fm-directory-view-list.c (fm_directory_view_list_get_selection): src/file-manager/fm-directory-view.c (display_selection_info), (display_pending_files), (add_files_cb), (open_in_new_window_cb), (fm_directory_view_real_append_selection_context_menu_items): Got rid of use of NautilusFileList typedef, corrected ref. counting of files in the lists by using new calls. * src/nautilus-bookmarklist.c, src/nautilus-bookmarks-menu.c, src/nautilus-index-tabs.c, src/file-manager/fm-directory-view-icons.c, src/file-manager/fm-directory-view.c, src/file-manager/fm-icons-controller.c: A bit of reformatting.
2000-02-24 00:54:57 +00:00
<p><b>We use the most-recommended coding style from the GNOME Programming
2000-02-15 20:55:05 +00:00
Guidelines.</b> This means that we use the Linux kernel brace style with
Some of the underlying work to prepare for emblems on the icons. * style-guide.html: Some minor updates to the style guide, including rules about headers. * libnautilus/nautilus-icon-factory.h, libnautilus/nautilus-icon-factory.c: (nautilus_icon_factory_get_emblem_icons_for_file), (nautilus_scalable_icon_get), (nautilus_icon_factor_clear), (nautilus_icon_factory_load_file), (nautilus_gdk_pixbuf_composite_corner), (nautilus_icon_factor_load_icon), (nautilus_scalable_icon_hash), (nautilus_scalable_icon_equal), (nautilus_icon_factory_get_icon_for_file), (load_specific_image): Added interface for getting emblem icons for a file, and got rid of the symbolic-link overlay that was previously built into the icon. * libnautilus/gnome-icon-container.c (update_icon): Get pixbufs for all emblems and pass into the icon object. * libnautilus/nautilus-icons-controller.c (nautius_icons_controller_get_icon_image): src/file-manager/fm-icons-controller.h, src/file-manager/fm-icons-controller.c (fm_icons_controller_get_icon_image): Return a list of emblem images along with the main image. * libnautilus/nautilus-icons-view-icon-item.h, libnautilus/nautilus-icons-view-icon-item.c (nautilus_icons_view_icon_item_set_emblems), (nautilus_icons_view_icon_item_destroy): Keep a list of emblem pixbufs in each icon. We don't draw them quite yet. * libnautilus/gdk-extensions.h, libnautilus/gdk-extensions.c: (nautilus_gdk_pixbuf_list_ref), (nautilus_gdk_pixbuf_list_unref), (nautilus_gdk_pixbuf_list_free): Convenience functions for manipulating lists of GdkPixbuf objects. * libnautilus/nautilus-directory.h, libnautilus/nautilus-directory.c: (nautilus_file_list_ref), (nautilus_file_list_unref), (nautilus_file_list_free): Convenience functions for manipulating lists of NautilusFile objects. Also got rid of NautilusFileList typedef. * libnautilus/nautilus-icon-factory.h, libnautilus/nautilus-icon-factory.h: (nautilus_scalable_icon_list_free): Convenience function for manipulating lists of NautilusScalableIcon objects. * libnautilus/nautilus-glib-extensions.h, libnautilus/nautilus-glib-extensions.c: (nautilus_g_list_equal): Function to compare two GLists to see if they are identical. Particularly useful with lists of reference-counted objects. * src/file-manager/fm-directory-view-icons.c (fm_directory_view_icons_destroy), (add_icon_if_already_positioned), (fm_directory_view_icons_append_selection_context_menu_items), (display_icons_not_already_positioned), (fm_direectory_view_icons_get_selection): src/file-manager/fm-directory-view-list.c (fm_directory_view_list_get_selection): src/file-manager/fm-directory-view.c (display_selection_info), (display_pending_files), (add_files_cb), (open_in_new_window_cb), (fm_directory_view_real_append_selection_context_menu_items): Got rid of use of NautilusFileList typedef, corrected ref. counting of files in the lists by using new calls. * src/nautilus-bookmarklist.c, src/nautilus-bookmarks-menu.c, src/nautilus-index-tabs.c, src/file-manager/fm-directory-view-icons.c, src/file-manager/fm-directory-view.c, src/file-manager/fm-icons-controller.c: A bit of reformatting.
2000-02-24 00:54:57 +00:00
8-character tabs (not the GNU brace style), we put spaces before
the parentheses that introduce function argument lists, we put the
braces that open the block for an if statement on the same line as the
if statement (part of Linux kernel brace style).</p>
2000-02-15 20:55:05 +00:00
<p><b>We prefer to use words rather than acronyms or abbreviations.</b> This means that
Wrote a script to check for files that forget to include <config.h> and * check-config-h.pl: Wrote a script to check for files that forget to include <config.h> and optionally edit to add it. * src/nautilus-zoom-control.c (set_zoom_level): Fixed the bug number in a FIXME. * docs/style-guide.html: Added one more tip. * check-FIXME.pl: Use my newfound Perl knowledge to spruce it up. * components/help/converters/gnome-db2html2/gdb3html.c: * components/help/converters/gnome-db2html2/sect-elements.c: * components/help/converters/gnome-db2html2/sect-preparse.c: * components/help/converters/gnome-db2html2/toc-elements.c: * components/help/converters/gnome-info2html2/html.c: * components/help/converters/gnome-info2html2/main.c: * components/help/converters/gnome-info2html2/parse.c: * components/help/converters/gnome-info2html2/utils.c: * components/help/converters/gnome-man2html2/gnome-man2html.c: * components/help/hyperbola-filefmt.c: * components/help/hyperbola-nav-index.c: * components/help/hyperbola-nav-search.c: * components/help/hyperbola-nav-tree.c: * components/html/glibwww-callbacks.c: * components/html/glibwww-init.c: * components/html/glibwww-trans.c: * components/html/gnome-dialogs.c: * components/html/ntl-web-browser.c: * components/services/install/eazel-install-metadata.c: * components/services/install/eazel-install-protocols.c: * components/services/install/eazel-install-rpm-glue.c: * components/services/install/eazel-install-tests.c: * components/services/install/eazel-install-utils.c: * components/services/install/eazel-install-xml-package-list.c: * components/services/install/eazel-install.c: * components/services/install/helixcode-install-utils.c: * components/services/startup/eazel-register.c: * components/websearch/ntl-web-search.c: * helper-utilities/authenticate/nautilus-authenticate-fork.c: * helper-utilities/authenticate/nautilus-authenticate-pam.c: * helper-utilities/authenticate/nautilus-authenticate.c: * libnautilus-extensions/nautilus-bonobo-extensions.c: * libnautilus-extensions/nautilus-file-utilities.c: * libnautilus-extensions/nautilus-glib-extensions.c: * libnautilus-extensions/nautilus-link.c: * libnautilus-extensions/nautilus-mime-type.c: * libnautilus-extensions/nautilus-undo-transaction.c: * librsvg/art_rgba.c: * librsvg/art_rgba_svp.c: * librsvg/rsvg-bpath-util.c: * librsvg/rsvg-path.c: * librsvg/rsvg.c: * librsvg/test-rsvg.c: * nautilus-widgets/nautilus-caption-table.c: * nautilus-widgets/nautilus-password-dialog.c: * nautilus-widgets/nautilus-preferences-box.c: * nautilus-widgets/nautilus-preferences-dialog.c: * nautilus-widgets/nautilus-preferences-group.c: * nautilus-widgets/nautilus-preferences-item.c: * nautilus-widgets/nautilus-preferences-pane.c: * nautilus-widgets/nautilus-radio-button-group.c: * nautilus-widgets/test-nautilus-widgets.c: * nautilus-widgets/test-preferences.c: * src/file-manager/desktop-item.c: * src/file-manager/desktop-layout.c: * src/file-manager/desktop-menu.c: * src/nautilus-bookmarks-window.c: * src/nautilus-gconf.c: * src/nautilus-window-menus.c: * src/nautilus-window-toolbars.c: * src/nautilus-zoom-control.c * src/nautilus-zoomable-frame-svr.c: * src/ntl-app.c: * src/ntl-content-view.c: * src/ntl-main.c: * src/ntl-meta-view.c: * src/ntl-miniicon.c: * src/ntl-uri-map.c: * src/ntl-view-frame-svr.c: * src/ntl-view.c: * src/ntl-window-state.c: Added includes of <config.h>.
2000-05-02 00:50:32 +00:00
we name classes with a prefix like Nautilus, not Ntl, for example. And we use variables
named result rather than retval or rv.</p>
2000-02-15 20:55:05 +00:00
<p><b>We strive to have a minimum number of local variables.</b> This makes it
easier to move pieces of code around. For more on this, read
<a href="recommended-books.html#Refactoring"><i>Refactoring</i></a>.</p>
<p><b>We use type casts as little as possible.</b> There are many places in GTK programming
where you have to cast to make the program work, but we do whatever we can
to avoid this. Also, we prefer to cast data pointers, rather than casting
function pointers, since there's so much more to get wrong with function
pointer casts.</p>
Some FIXME cleanup. * components/help/converters/gnome-db2html2/sect-elements.c: (sect_article_end_element), (sect_inlinegraphic_start_element): * components/help/converters/gnome-db2html2/toc-elements.c: (toc_sect_end_element): * components/mozilla/mozilla-events.cpp: * components/mozilla/nautilus-mozilla-content-view.c: (make_full_uri_from_relative), (eazel_services_scheme_translate): * components/music/nautilus-music-view.c: (nautilus_music_view_initialize), (music_view_set_selected_song_title), (reset_playtime), (play_status_display), (slider_moved_callback), (add_play_controls): * components/notes/nautilus-notes.c: (notes_load_metainfo): * components/services/install/lib/eazel-install-logic.c: (eazel_install_check_for_file_conflicts), (eazel_install_do_transaction_all_files_check), (eazel_install_prune_packages_helper), (eazel_install_check_existing_packages): * libnautilus-extensions/nautilus-string.c: (nautilus_strcmp), (nautilus_strcasecmp), (nautilus_strcmp_case_breaks_ties), (nautilus_strcoll), (nautilus_str_is_equal), (nautilus_istr_is_equal), (nautilus_strcmp_compare_func), (nautilus_strcoll_compare_func), (nautilus_strcasecmp_compare_func): * src/file-manager/fm-directory-view.c: (open_location): * src/nautilus-first-time-druid.c: (make_anti_aliased_label), (make_hbox_user_level_radio_button), (set_up_user_level_page): Added bug numbers to FIXMEs. At one point Josh made some bugs for FIXMEs but never got around to checking in the bug numbers in the source code. And I wrote one bug report. * components/music/nautilus-music-view.c: (nautilus_music_view_initialize): Removed a fixed FIXME. Also got rid of a hard-coded constant and took excess spaces out of some string constants. * components/services/install/lib/eazel-install-object.c: (eazel_install_emit_dependency_check_default): Changed a FIXME into a non-FIXME comment, now the the bug is fixed. * components/services/install/lib/eazel-package-system-rpm3.c: (rpm_packagedata_fill_from_file): Removed an incorrect bug number from a FIXME. * components/services/install/nautilus-view/nautilus-service-install-view.h: * components/services/install/nautilus-view/nautilus-service-install-view.c: (nautilus_service_install_installing): Removed the FIXME from a comment that's about how a bug was fixed. * components/services/trilobite/libtrilobite/trilobite-md5-tools.h: * components/services/trilobite/libtrilobite/trilobite-md5-tools.c: * docs/style-guide.html: Removed FIXME and corrected misunderstanding about whether use of the guchar typedef is recommended in Nautilus coding style. * libnautilus-extensions/nautilus-gdk-font-extensions.h: * libnautilus-extensions/nautilus-gdk-font-extensions.c: Removed misguided use of const in here. Gdk and Gtk object types just aren't suitable for const, and you end up doing type casts that defeat the purpose. * src/nautilus-window-manage-views.c: (load_underway_callback): Remove a FIXME for a fixed bug.
2001-01-05 02:03:34 +00:00
<p><b>We use typedefs from &lt;glib.h&gt; for things like guint, guchar and gpointer,
2000-02-15 20:55:05 +00:00
but not gint, gchar, or gdouble.</b> Using these gives a false sense
of portability. In all three cases, using system calls like printf requires
Some of the underlying work to prepare for emblems on the icons. * style-guide.html: Some minor updates to the style guide, including rules about headers. * libnautilus/nautilus-icon-factory.h, libnautilus/nautilus-icon-factory.c: (nautilus_icon_factory_get_emblem_icons_for_file), (nautilus_scalable_icon_get), (nautilus_icon_factor_clear), (nautilus_icon_factory_load_file), (nautilus_gdk_pixbuf_composite_corner), (nautilus_icon_factor_load_icon), (nautilus_scalable_icon_hash), (nautilus_scalable_icon_equal), (nautilus_icon_factory_get_icon_for_file), (load_specific_image): Added interface for getting emblem icons for a file, and got rid of the symbolic-link overlay that was previously built into the icon. * libnautilus/gnome-icon-container.c (update_icon): Get pixbufs for all emblems and pass into the icon object. * libnautilus/nautilus-icons-controller.c (nautius_icons_controller_get_icon_image): src/file-manager/fm-icons-controller.h, src/file-manager/fm-icons-controller.c (fm_icons_controller_get_icon_image): Return a list of emblem images along with the main image. * libnautilus/nautilus-icons-view-icon-item.h, libnautilus/nautilus-icons-view-icon-item.c (nautilus_icons_view_icon_item_set_emblems), (nautilus_icons_view_icon_item_destroy): Keep a list of emblem pixbufs in each icon. We don't draw them quite yet. * libnautilus/gdk-extensions.h, libnautilus/gdk-extensions.c: (nautilus_gdk_pixbuf_list_ref), (nautilus_gdk_pixbuf_list_unref), (nautilus_gdk_pixbuf_list_free): Convenience functions for manipulating lists of GdkPixbuf objects. * libnautilus/nautilus-directory.h, libnautilus/nautilus-directory.c: (nautilus_file_list_ref), (nautilus_file_list_unref), (nautilus_file_list_free): Convenience functions for manipulating lists of NautilusFile objects. Also got rid of NautilusFileList typedef. * libnautilus/nautilus-icon-factory.h, libnautilus/nautilus-icon-factory.h: (nautilus_scalable_icon_list_free): Convenience function for manipulating lists of NautilusScalableIcon objects. * libnautilus/nautilus-glib-extensions.h, libnautilus/nautilus-glib-extensions.c: (nautilus_g_list_equal): Function to compare two GLists to see if they are identical. Particularly useful with lists of reference-counted objects. * src/file-manager/fm-directory-view-icons.c (fm_directory_view_icons_destroy), (add_icon_if_already_positioned), (fm_directory_view_icons_append_selection_context_menu_items), (display_icons_not_already_positioned), (fm_direectory_view_icons_get_selection): src/file-manager/fm-directory-view-list.c (fm_directory_view_list_get_selection): src/file-manager/fm-directory-view.c (display_selection_info), (display_pending_files), (add_files_cb), (open_in_new_window_cb), (fm_directory_view_real_append_selection_context_menu_items): Got rid of use of NautilusFileList typedef, corrected ref. counting of files in the lists by using new calls. * src/nautilus-bookmarklist.c, src/nautilus-bookmarks-menu.c, src/nautilus-index-tabs.c, src/file-manager/fm-directory-view-icons.c, src/file-manager/fm-directory-view.c, src/file-manager/fm-icons-controller.c: A bit of reformatting.
2000-02-24 00:54:57 +00:00
knowing that these are the "real" int, char, and double, so there's no reason
Some FIXME cleanup. * components/help/converters/gnome-db2html2/sect-elements.c: (sect_article_end_element), (sect_inlinegraphic_start_element): * components/help/converters/gnome-db2html2/toc-elements.c: (toc_sect_end_element): * components/mozilla/mozilla-events.cpp: * components/mozilla/nautilus-mozilla-content-view.c: (make_full_uri_from_relative), (eazel_services_scheme_translate): * components/music/nautilus-music-view.c: (nautilus_music_view_initialize), (music_view_set_selected_song_title), (reset_playtime), (play_status_display), (slider_moved_callback), (add_play_controls): * components/notes/nautilus-notes.c: (notes_load_metainfo): * components/services/install/lib/eazel-install-logic.c: (eazel_install_check_for_file_conflicts), (eazel_install_do_transaction_all_files_check), (eazel_install_prune_packages_helper), (eazel_install_check_existing_packages): * libnautilus-extensions/nautilus-string.c: (nautilus_strcmp), (nautilus_strcasecmp), (nautilus_strcmp_case_breaks_ties), (nautilus_strcoll), (nautilus_str_is_equal), (nautilus_istr_is_equal), (nautilus_strcmp_compare_func), (nautilus_strcoll_compare_func), (nautilus_strcasecmp_compare_func): * src/file-manager/fm-directory-view.c: (open_location): * src/nautilus-first-time-druid.c: (make_anti_aliased_label), (make_hbox_user_level_radio_button), (set_up_user_level_page): Added bug numbers to FIXMEs. At one point Josh made some bugs for FIXMEs but never got around to checking in the bug numbers in the source code. And I wrote one bug report. * components/music/nautilus-music-view.c: (nautilus_music_view_initialize): Removed a fixed FIXME. Also got rid of a hard-coded constant and took excess spaces out of some string constants. * components/services/install/lib/eazel-install-object.c: (eazel_install_emit_dependency_check_default): Changed a FIXME into a non-FIXME comment, now the the bug is fixed. * components/services/install/lib/eazel-package-system-rpm3.c: (rpm_packagedata_fill_from_file): Removed an incorrect bug number from a FIXME. * components/services/install/nautilus-view/nautilus-service-install-view.h: * components/services/install/nautilus-view/nautilus-service-install-view.c: (nautilus_service_install_installing): Removed the FIXME from a comment that's about how a bug was fixed. * components/services/trilobite/libtrilobite/trilobite-md5-tools.h: * components/services/trilobite/libtrilobite/trilobite-md5-tools.c: * docs/style-guide.html: Removed FIXME and corrected misunderstanding about whether use of the guchar typedef is recommended in Nautilus coding style. * libnautilus-extensions/nautilus-gdk-font-extensions.h: * libnautilus-extensions/nautilus-gdk-font-extensions.c: Removed misguided use of const in here. Gdk and Gtk object types just aren't suitable for const, and you end up doing type casts that defeat the purpose. * src/nautilus-window-manage-views.c: (load_underway_callback): Remove a FIXME for a fixed bug.
2001-01-05 02:03:34 +00:00
to use a typedef that's non-standard unless it's a shorter name or clearer
in some way.</p>
2000-02-15 20:55:05 +00:00
<p><b>We avoid in-band signaling.</b> This means that we avoid using special
values to indicate errors, for example. This can lead to subtle bugs when a valid
result is misinterpreted as an error, and can make it hard to tell if the code
handles errors or not.</p>
Some of the underlying work to prepare for emblems on the icons. * style-guide.html: Some minor updates to the style guide, including rules about headers. * libnautilus/nautilus-icon-factory.h, libnautilus/nautilus-icon-factory.c: (nautilus_icon_factory_get_emblem_icons_for_file), (nautilus_scalable_icon_get), (nautilus_icon_factor_clear), (nautilus_icon_factory_load_file), (nautilus_gdk_pixbuf_composite_corner), (nautilus_icon_factor_load_icon), (nautilus_scalable_icon_hash), (nautilus_scalable_icon_equal), (nautilus_icon_factory_get_icon_for_file), (load_specific_image): Added interface for getting emblem icons for a file, and got rid of the symbolic-link overlay that was previously built into the icon. * libnautilus/gnome-icon-container.c (update_icon): Get pixbufs for all emblems and pass into the icon object. * libnautilus/nautilus-icons-controller.c (nautius_icons_controller_get_icon_image): src/file-manager/fm-icons-controller.h, src/file-manager/fm-icons-controller.c (fm_icons_controller_get_icon_image): Return a list of emblem images along with the main image. * libnautilus/nautilus-icons-view-icon-item.h, libnautilus/nautilus-icons-view-icon-item.c (nautilus_icons_view_icon_item_set_emblems), (nautilus_icons_view_icon_item_destroy): Keep a list of emblem pixbufs in each icon. We don't draw them quite yet. * libnautilus/gdk-extensions.h, libnautilus/gdk-extensions.c: (nautilus_gdk_pixbuf_list_ref), (nautilus_gdk_pixbuf_list_unref), (nautilus_gdk_pixbuf_list_free): Convenience functions for manipulating lists of GdkPixbuf objects. * libnautilus/nautilus-directory.h, libnautilus/nautilus-directory.c: (nautilus_file_list_ref), (nautilus_file_list_unref), (nautilus_file_list_free): Convenience functions for manipulating lists of NautilusFile objects. Also got rid of NautilusFileList typedef. * libnautilus/nautilus-icon-factory.h, libnautilus/nautilus-icon-factory.h: (nautilus_scalable_icon_list_free): Convenience function for manipulating lists of NautilusScalableIcon objects. * libnautilus/nautilus-glib-extensions.h, libnautilus/nautilus-glib-extensions.c: (nautilus_g_list_equal): Function to compare two GLists to see if they are identical. Particularly useful with lists of reference-counted objects. * src/file-manager/fm-directory-view-icons.c (fm_directory_view_icons_destroy), (add_icon_if_already_positioned), (fm_directory_view_icons_append_selection_context_menu_items), (display_icons_not_already_positioned), (fm_direectory_view_icons_get_selection): src/file-manager/fm-directory-view-list.c (fm_directory_view_list_get_selection): src/file-manager/fm-directory-view.c (display_selection_info), (display_pending_files), (add_files_cb), (open_in_new_window_cb), (fm_directory_view_real_append_selection_context_menu_items): Got rid of use of NautilusFileList typedef, corrected ref. counting of files in the lists by using new calls. * src/nautilus-bookmarklist.c, src/nautilus-bookmarks-menu.c, src/nautilus-index-tabs.c, src/file-manager/fm-directory-view-icons.c, src/file-manager/fm-directory-view.c, src/file-manager/fm-icons-controller.c: A bit of reformatting.
2000-02-24 00:54:57 +00:00
<p><b>We code for clarity first.</b> Other concerns like efficiency are secondary.
Sometimes they become more important than clarity, but only once they are proven
to be a problem.</p>
2000-02-15 20:55:05 +00:00
2000-03-25 02:38:49 +00:00
<p><b>We use for loops when they make the code easier to read.</b> The alternative
is usually to use a while loop. It's true that
2000-02-15 20:55:05 +00:00
"easy to read" is a subjective thing.</p>
<p><b>We declare local variables at the beginning of a block.</b> C99 allows you
to declare variables anywhere in a function, but a lot of compilers still do not
support C99.</p>
2000-03-25 02:38:49 +00:00
<p><b>We do not initialize local variables in their declarations.</b> C allows you
to initialize a local variable when declaring it. But no other code can run before
this, because the other statements in a function must be after all the declarations.
If there are lines of code initializing the variables in the declarations, it can
be harder to change the function around, since code must move down from the declaration
if other code needs to run after it. To avoid this, we just don't use the ability
to initialize the variable when it's declared.</p>
<p><b>We always use braces, even for one-statement "blocks".</b> Our consensus is
to do things like this:</p>
<blockquote>
<pre>
if (list != NULL) {
g_warning ("the list isn't empty");
}
</pre>
</blockquote>
<p>Instead of this:</p>
<blockquote>
<pre>
if (list != NULL)
g_warning ("the list isn't empty");
</pre>
</blockquote>
<p>This applies to all control structures: if, while, for, do.</p>
Some of the underlying work to prepare for emblems on the icons. * style-guide.html: Some minor updates to the style guide, including rules about headers. * libnautilus/nautilus-icon-factory.h, libnautilus/nautilus-icon-factory.c: (nautilus_icon_factory_get_emblem_icons_for_file), (nautilus_scalable_icon_get), (nautilus_icon_factor_clear), (nautilus_icon_factory_load_file), (nautilus_gdk_pixbuf_composite_corner), (nautilus_icon_factor_load_icon), (nautilus_scalable_icon_hash), (nautilus_scalable_icon_equal), (nautilus_icon_factory_get_icon_for_file), (load_specific_image): Added interface for getting emblem icons for a file, and got rid of the symbolic-link overlay that was previously built into the icon. * libnautilus/gnome-icon-container.c (update_icon): Get pixbufs for all emblems and pass into the icon object. * libnautilus/nautilus-icons-controller.c (nautius_icons_controller_get_icon_image): src/file-manager/fm-icons-controller.h, src/file-manager/fm-icons-controller.c (fm_icons_controller_get_icon_image): Return a list of emblem images along with the main image. * libnautilus/nautilus-icons-view-icon-item.h, libnautilus/nautilus-icons-view-icon-item.c (nautilus_icons_view_icon_item_set_emblems), (nautilus_icons_view_icon_item_destroy): Keep a list of emblem pixbufs in each icon. We don't draw them quite yet. * libnautilus/gdk-extensions.h, libnautilus/gdk-extensions.c: (nautilus_gdk_pixbuf_list_ref), (nautilus_gdk_pixbuf_list_unref), (nautilus_gdk_pixbuf_list_free): Convenience functions for manipulating lists of GdkPixbuf objects. * libnautilus/nautilus-directory.h, libnautilus/nautilus-directory.c: (nautilus_file_list_ref), (nautilus_file_list_unref), (nautilus_file_list_free): Convenience functions for manipulating lists of NautilusFile objects. Also got rid of NautilusFileList typedef. * libnautilus/nautilus-icon-factory.h, libnautilus/nautilus-icon-factory.h: (nautilus_scalable_icon_list_free): Convenience function for manipulating lists of NautilusScalableIcon objects. * libnautilus/nautilus-glib-extensions.h, libnautilus/nautilus-glib-extensions.c: (nautilus_g_list_equal): Function to compare two GLists to see if they are identical. Particularly useful with lists of reference-counted objects. * src/file-manager/fm-directory-view-icons.c (fm_directory_view_icons_destroy), (add_icon_if_already_positioned), (fm_directory_view_icons_append_selection_context_menu_items), (display_icons_not_already_positioned), (fm_direectory_view_icons_get_selection): src/file-manager/fm-directory-view-list.c (fm_directory_view_list_get_selection): src/file-manager/fm-directory-view.c (display_selection_info), (display_pending_files), (add_files_cb), (open_in_new_window_cb), (fm_directory_view_real_append_selection_context_menu_items): Got rid of use of NautilusFileList typedef, corrected ref. counting of files in the lists by using new calls. * src/nautilus-bookmarklist.c, src/nautilus-bookmarks-menu.c, src/nautilus-index-tabs.c, src/file-manager/fm-directory-view-icons.c, src/file-manager/fm-directory-view.c, src/file-manager/fm-icons-controller.c: A bit of reformatting.
2000-02-24 00:54:57 +00:00
<p><b>We make each header "stand alone".</b> Our concept with C header files is
that each one must be written so it can be included without including another file
first. To test that the header files we develop have this property, we always
include the corresponding header file first in each C source file. The only exception
is the include of &lt;config.h>, which goes first. Here's an example:</p>
<blockquote>
<pre>
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
*
* nautilus-icon-factory.c: Class for obtaining icons for files and other objects.
*
* Copyright (C) 1999, 2000 Red Hat Inc.
* Copyright (C) 1999, 2000 Eazel, Inc.
*
* <i>License agreement goes here.</i>
*
* Author: John Sullivan &lt;sullivan@eazel.com>
*/
#include &lt;config.h>
#include "nautilus-icon-factory.h"
#include &lt;string.h>
#include &lt;stdio.h>
<i>Include statements for other header files go here.</i>
<i>Other declarations and code go here.</i>
</pre>
</blockquote>
2000-03-25 02:38:49 +00:00
<hr>
2000-02-15 20:55:05 +00:00
</body>
</html>