[gnome-boxes] CodingStyle: add rulez about multiple returned values
- From: Marc-Andre Lureau <malureau src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] CodingStyle: add rulez about multiple returned values
- Date: Mon, 30 Jul 2012 17:13:25 +0000 (UTC)
commit d1a36c6f0afdc9bd830cc6b86be987b1e3f9b170
Author: Marc-Andrà Lureau <marcandre lureau gmail com>
Date: Wed Jul 18 14:40:46 2012 +0200
CodingStyle: add rulez about multiple returned values
Some proposal to spice up the day while Zeeshan is on holiday :)
Just kidding, we should try to convince him in GUADEC!
* If a function returns several equally important values, they should
all be given as out arguments. IOW, prefer this:
void get_a_and_b (out string a, out string b)
rather than the un-even, string get_a_and_b (out b)
https://bugzilla.gnome.org/show_bug.cgi?id=680166
CodingStyle.txt | 7 +++++++
src/vm-creator.vala | 10 ++++------
2 files changed, 11 insertions(+), 6 deletions(-)
---
diff --git a/CodingStyle.txt b/CodingStyle.txt
index d58aaf2..3aff76d 100644
--- a/CodingStyle.txt
+++ b/CodingStyle.txt
@@ -94,3 +94,10 @@ from the Rygel Coding Style.
default:
...
}
+
+ * If a function returns several equally important values, they should
+ all be given as out arguments. IOW, prefer this:
+
+ void get_a_and_b (out string a, out string b)
+
+ rather than the un-even, string get_a_and_b (out b)
diff --git a/src/vm-creator.vala b/src/vm-creator.vala
index f03dd60..83a1227 100644
--- a/src/vm-creator.vala
+++ b/src/vm-creator.vala
@@ -32,8 +32,8 @@ private class Boxes.VMCreator {
yield;
}
- string title;
- var name = yield create_domain_name_and_title_from_media (out title);
+ string title, name;
+ yield create_domain_name_and_title_from_media (out name, out title);
yield install_media.prepare_for_installation (name, cancellable);
var volume = yield create_target_volume (name, install_media.resources.storage);
@@ -152,13 +152,13 @@ private class Boxes.VMCreator {
}
}
- private async string create_domain_name_and_title_from_media (out string title) throws GLib.Error {
+ private async void create_domain_name_and_title_from_media (out string name, out string title) throws GLib.Error {
var base_title = install_media.label;
title = base_title;
var base_name = (install_media.os != null) ? install_media.os.short_id : base_title;
if (install_media.live)
base_name += "-live";
- var name = base_name;
+ name = base_name;
var pool = yield get_storage_pool ();
for (var i = 2;
@@ -169,8 +169,6 @@ private class Boxes.VMCreator {
name = base_name + "-" + i.to_string ();
title = base_title + " " + i.to_string ();
}
-
- return name;
}
private async StorageVol create_target_volume (string name, int64 storage) throws GLib.Error {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]