File: HACKING

package info (click to toggle)
smuxi 0.11~rc5-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 24,200 kB
  • ctags: 36,112
  • sloc: cs: 217,265; sh: 11,486; makefile: 2,136
file content (98 lines) | stat: -rw-r--r-- 2,513 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
See https://www.smuxi.org/page/HackingHowto

Coding Style
============

using System;
using System.IO;
using ThirdPartyNamespaces;
using MyOwnNamespaces;

namespace Smuxi.Frontend.Gnome
{
    public class GroupChatView : ChatView
    {
        // fields before auto properties
        int f_SomeField;
        string f_AnotherField;
        public int SomeAutoProperty { get; set; }

        // properties before ctors
        public int SomeManualProperty {
            get {
                return f_SomeField;
            }
            set {
                f_SomeField = value;
            }
        }

        // events before ctors
        public event EventHandler<EventArgs> StatusChanged;

        // ctors before methods
        public ChatView()
        {
        }

        public ChatView(int someParameter, string anotherParameter) :
                   base(someParameter, anotherParameter)
        {
            SomeAutoProperty = someParameter;
            f_AnotherField = anotherParameter;
        }

        public void SomePublicMethod()
        {
            // avoid nesting
            if (f_SomeField != 0) {
                return;
            }

            DoSomething();

            var res = MethodCallWithLotsOfParameterThatDontFitInASingleLine(
                f_SomeField,
                f_AnotherField,
                String.Format(
                    "Some String with {0}",
                    SomeAutoProperty
                )
            );

            switch (res) {
                case "Foo":
                    // code of Foo case
                    break;
                case "Bar":
                    // code of Bar case
                    break;
            }
        }

        // do not specify default access modifiers (private for methods)
        void DoSomething()
        {
            try {
                using (var hardStuff = GetSomethingHard()) {
                    // this is too hard, can't deal with it
                }
            } catch (InvalidOperationException) {
            }

            // do not use if (!something) with a else case, instead do:
            if (something) {
                // something is true case
            } else {
                // something is false case
            }

            // fluent style
            var msg = CreateMessageBuilder().
                AppendEventPrefix().
                AppendFormat("Test message").
                ToMessage();
            AddMessage(msg);
        }
    }
}