coding-style

Is effective C++ still effective?

﹥>﹥吖頭↗ 提交于 2019-12-04 07:24:09
问题 From what I saw in this post I decided to start reading the book Effective C++. But now that there are many new features because of C++11 and that a few of the good practices changed, I'm not sure whether or not it is actually a good idea. Has the advent of C++11 deprecated any of the advice contained in Effective C++? If so, which topics should I avoid? 回答1: This what Scott Meyers himself had to say about it on his own blog Which may lead you to wonder whether the information and advice in

Better way to write large SQLs inside rails models?

流过昼夜 提交于 2019-12-04 07:22:33
After using a lot of Arel that Rails provides for sugar code, I am having problems when dealing with large and complex SQLs queries that I couldn't do it very well with Arel methods. I like Arel for little things, but when it get messy I prefer separate the code. So, is there any advice on how should I be treating my large SQLs inside models? Like, when should I create SQL Views for that (as I seen Rails do not provide very well, I have to create a migration for that) or create any separate classes in some folder "sqls" and then call from there. I know that some people use the <<-SQL

What is the 'Null coalesce' (??) operator used for? [closed]

早过忘川 提交于 2019-12-04 07:13:20
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . With the release of a new PHP version, PHP 7, new features are introduced. among these new features is an operator I am not familiar with. The Null coalesce operator . What is this operator and what are some good use cases? 回答1: You can use it to init a variable that might be null The ?? operator is called the

Is iteration slower than linear code? Which one is preferable?

心已入冬 提交于 2019-12-04 07:06:23
问题 This question was migrated from Software Engineering Stack Exchange because it can be answered on Stack Overflow. Migrated 7 years ago . I have a question in my mind from last many days, that while writing a code in ruby, is the linear code is faster and preferable than an iteration? Let me have an example. There is a block of code for same functionality written in two different ways: Way 1: ['dog', 'cat', 'tiger'].each do |pet_name| puts "I have many pets, one of them is #{pet_name}." end

Bash convention for if ; then

二次信任 提交于 2019-12-04 06:44:43
From this web page : http://tldp.org/LDP/abs/html/abs-guide.html It's mentioned the usage of the if bracket then convention which need a space after the semicolon : ; Command separator [semicolon]. Permits putting two or more commands on the same line. echo hello; echo there if [ -x "$filename" ]; then # Note the space after the semicolon. #+ ^^ echo "File $filename exists."; cp $filename $filename.bak else # ^^ echo "File $filename not found."; touch $filename fi; echo "File test complete." Note that the ";" sometimes needs to be escaped. Does anyone know where is this coming from and if this

Why maintain traditional detailed ChangeLog in modern world (with SVN, Mercurial, Git)?

时光总嘲笑我的痴心妄想 提交于 2019-12-04 06:37:55
Detailed ChangeLog entry usually tell who, when and what function changed and for why this change done. And this for every separate function in the source code tree! As I understand ChangeLog come from past when there were no good VCS. So traditional ChangeLog doesn't need at all as you can get it all from: $ svn log . $ hg log . $ git log . $ bzr log . Only one possible needs for ChangeLog for short summary between product versions and intended for user only (for example, when new version come, developer prepare ChangeLog describe notable/visible changes). Or I am wrong? From http:/

Can I create a new struct on the heap without defining a constructor?

拜拜、爱过 提交于 2019-12-04 05:48:20
I understand that there are very few differences between structs and classes in c++ (two?). Be that as it may, I've been instructed to use structs to define simple little things like nodes that might not need member functions (despite the fact that I could technically include include member functions). For instance I might define a node as a private member of a linked list class as follows: class LinkedList { struct Node { MyObject *data; Node *next; }; Node *list; }; In this case, however, is it possible to create a new instance of this struct on the heap, or would I need to define a

TextView state_pressed/state_focused/state_selected style change

旧时模样 提交于 2019-12-04 05:09:58
I'm trying to change a TextView style based on its state. My styles.xml contains: <style name="text_normal_ops"> <item name="android:gravity">left</item> <item name="android:textColor">@color/text_usual_color</item> <item name="android:textStyle">bold</item> </style> <style name="text_normal_ops_pressed"> <item name="android:gravity">left</item> <item name="android:textColor">@color/text_pressed</item> <item name="android:textStyle">bold</item> </style> My selector ( text_ops.xml )is defined as: <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed=

Why use = to initialise a primitive type in C++?

不想你离开。 提交于 2019-12-04 05:00:27
Where I work, people mostly think that objects are best initialised using C++-style construction (with parentheses), whereas primitive types should be initialised with the = operator: std::string strFoo( "Foo" ); int nBar = 5; Nobody seems to be able to explain why they prefer things this way, though. I can see that std::string = "Foo"; would be inefficient because it would involve an extra copy, but what's wrong with just banishing the = operator altogether and using parentheses everywhere? Is it a common convention? What's the thinking behind it? Unless you've proven that it matters with

Full-bleed background videos?

邮差的信 提交于 2019-12-04 04:44:11
问题 I'm wondering if anyone has thought about or come across any realistic methods for providing a full bleed background VIDEO to a site, without resulting in the site being dead slow. Ideally I don't want to have to use Flash. And By full bleed I mean from edge to edge of the screen, like a desktop wallpaper. 回答1: Wait for HTML 5? 回答2: If you dont want flash then try using silverlight. 回答3: Since the rendering of the video (in whatever way it would work) is always done on the client, the