coding-style

C++: Drawbacks to writing whole classes in Header files for small projects?

淺唱寂寞╮ 提交于 2020-01-03 07:50:27
问题 Just a style question... I'm a lowly indie game dev working by myself, and I developed what I have been told is a 'bad' habit of writing whole classes in my headers. Some of the benefits I know .h/.cpp file combos have are they allow code to be split into compilation chunks that won't need recompiled so long as they remain unchanged. And allows for splitting interface from implementation. However, neither of those things are of any benefit to me, since I tend to favour having my

Can I avoid “rightward drift” in Haskell?

感情迁移 提交于 2020-01-03 07:18:12
问题 When I use an imperative language I often write code like foo (x) { if (x < 0) return True; y = getForX(x); if (y < 0) return True; return x < y; } That is, I check conditions off one by one, breaking out of the block as soon as possible. I like this because it keeps the code "flat" and obeys the principle of "end weight". I consider it to be more readable. But in Haskell I would have written that as foo x = do if x < 0 then return x else do y <- getForX x if y < 0 then return True else

To use or not to use C++0x features [duplicate]

跟風遠走 提交于 2020-01-03 07:17:36
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: How are you using C++0x today? I'm working with a team on a fairly new system. We're talking about migrating to MSVC 2010 and we've already migrated to GCC 4.5. These are the only compilers we're using and we have no plans to port our code to different compilers any time soon. I suggested that after we do it, we start taking advantage of some of the C++0x features already provided like auto. My co-worker

Groovy SwingBuilder : controlling the style of the tabs titles in JTabbedPane

被刻印的时光 ゝ 提交于 2020-01-03 02:48:11
问题 I can't find a way (is there any ?) to format the style of tabs titles in a JTabbedPane. I can change the background color of the tab panes (see below), but can't find a way to style the titles of the tabs; I would like to have them bold or red or be able to define the tabs width, for instance, like I could format the style of the labels in the first panel. Here's the code, mostly inspired by tim_yates (Groovy SwingBuilder : using a scrollpanel to show a list of panels) : import groovy.swing

Whats the appropriate form when dispatching events in AS3?

二次信任 提交于 2020-01-02 13:15:15
问题 I was wondering what the appropriate form was when creating custom events? Should one create a CustomEvent class, and then create a temporary dispatcher in the function, and dispatch the CustomEvent. or is it better to attempt to create a CustomEventDispatcher class, and create the CustomEvent class as an internal class of that class, eg: package { public class CustomEventDispatcher extends EventDispatcher { public function CustomEventDispatcher() { super(new CustomEvent()); } } } class

naming of physical quantities in python

被刻印的时光 ゝ 提交于 2020-01-02 10:18:02
问题 I would like to establish a good naming scheme for physical/mathematical quantities used in my simulation code. Consider the following example: from math import * class GaussianBeamIntensity(object): """ Optical intensity profile of a Gaussian laser beam. """ def __init__(self, intensity_at_waist_center, waist_radius, wavelength): """ Arguments: *intensity_at_waist_center*: The optical intensity of the beam at the center of its waist in W/m^2 units. *waist_radius*: The radius of the beam

Is there a way to make eclipse report a general “catch (Exception e)” as an error/warning (in java)?

北城余情 提交于 2020-01-02 05:19:05
问题 I'm trying to encourage a best practice of not catching general exceptions in Java code. eg: try { ... } catch (Exception e) { // bad! ... } Is there a way to flag this as an error/warning in Eclipse? I know PMD picks this up, but I'd rather avoid integrating it into everyone's build environment at the moment. 回答1: You can use Checkstyle eclipse plugin to do the same. Check 'IllegalCatch' section at documentation 回答2: FindBugs can report this: REC : Exception is caught when Exception is not

Class method and instance method with the same name in Objective-C

妖精的绣舞 提交于 2020-01-02 02:35:17
问题 I have a solution for a notification problem which works well, but I'm afraid might be a bad idea. I have a notification that needs to be handled by each instance of a class and by the class itself. To handle this, I'm registering for a notification by both the class and instances of the class. Because it's the exact same notification, I've named the class and instance method the same. This follows the standard we've set for how notification handlers are named. Is this a bad idea? Is there

How could I indent C++ pragma using clang-format?

↘锁芯ラ 提交于 2020-01-02 01:09:17
问题 I am using vim-autoformat , which uses clang-format as external formatter. It seems that clang-format won't indent the C++ #pragma . For example: #include <omp.h> #include <cstdio> int main() { #pragma omp parallel for for (int i = 0; i < 10; ++i) { puts("demo"); } return 0; } I would like to have it formatted into : #include <omp.h> #include <cstdio> int main() { #pragma omp parallel for for (int i = 0; i < 10; ++i) { puts("demo"); } return 0; } I checked clangformat, but didn't find which

How to get the blue style text in 2.1 Contacts or Preferences

限于喜欢 提交于 2020-01-01 20:49:28
问题 Running Android 2.1, preferences and other dialogs have white/blue text. Looking at theme values I see things like textColorPrimary and textColorSecondary. If I reference those colors in my layout xml, with something like: android:textColor="?android:attr/textColorSecondary" I just see white text (I have tried textColorPrimary, textColorTertiary and textColorHint also). I do not have any theme values stated in my manifest file. I am presuming this means I am using the system default theme.