coding-style

May I write {x,a,b}//Do[…,#]& instead of Do[…,{x,a,b}]?

半城伤御伤魂 提交于 2019-12-04 04:33:33
I'm in love with Ruby. In this language all core functions are actually methods. That's why I prefer postfix notation – when the data, which I want to process is placed left from the body of anonymous processing function, for example: array.map{...} . I believe, that it has advantages in how easy is this code to read. But Mathetica, being functional (yeah, it can be procedural if you want) dictates a style, where Function name is placed left from the data. As we can see in its manuals, // is used only when it's some simple Function, without arguments, like list // MatrixForm . When Function

Accessor Method Performance and Optimization

橙三吉。 提交于 2019-12-04 04:28:14
Often, I come across code where the Getter method is repeatedly used/abused to get some value or pass it as a method parameter, for ex: public class Test { public void someMethod() { if(person.getName() != null && person.getName().equalsIgnoreCase("Einstein")) { method1(person.getName()); } method2(person.getName()); method3(person.getName()); method4(person.getName()); } } I usually code it, as below: public class Test { public void someMethod() { String name = person.getName(); if(name != null && name.equalsIgnoreCase("Einstein")) { method1(name); } method2(name); method3(name); method4(name

What is the best practice for writing sql queries inside c# code

烂漫一生 提交于 2019-12-04 04:16:05
On my current project I'm using SQL CE. Since it doesn't have support for stored procedures I have to write sql queries inside repository. Option 1: StringBuilder query = new StringBuilder(); query.Append("SELECT"); query.Append(" c.CUSTOMER_ID,"); query.Append(" COALESCE (c.FIRST_NAME, '') + ' ' + COALESCE (c.LAST_NAME, '') AS FULL_NAME"); query.Append(" ct.NAME as CUSTOMER_TYPE"); query.Append("FROM "); query.Append(" CT_CUSTOMER_TYPE AS ct INNER JOIN CUSTOMER AS c ON ct.CUSTOMER_TYPE_ID = c.CUSTOMER_TYPE_ID"); Option 2: string query = "SELECT c.CUSTOMER_ID, COALESCE (c.FIRST_NAME, '') + ' '

What are The Valid & Readable approaches to Commenting in PHP5?

时间秒杀一切 提交于 2019-12-04 04:13:05
In the past 2 months that I have been learning PHP, I have identified more than two styles people use to comment code! I haven't seen much consistency... which I think usually means artists at work . So I wondered: what are the valid ways to comment which are still readable/practical? Seeing all the valid possibilities in 1 place side by side will provide the overview that I am looking for to improve commenting /* | This is what I now use (5chars/3lines) I name it star*wars \* Quoting the Manual on Comments: PHP supports 'C', 'C++' and Unix shell-style (Perl style) comments. For example: <?php

HTML File upload field style

狂风中的少年 提交于 2019-12-04 03:40:06
问题 I am trying to create a file upload field that has a little bit of style to it, but I seem to be having problems finding examples of this. I know part of the reason is that the field itself varies from browser to browser. Any ideas how to do this? Or is there a way to do this without using a file element of a form that can be styled? 回答1: If what you mean is the text field for the file names, you can use the input[type=file] selector in the css files. For example : input[type=file] {

GCC optimization trick, does it really work?

纵然是瞬间 提交于 2019-12-04 03:25:37
While looking at some questions on optimization, this accepted answer for the question on coding practices for most effective use of the optimizer piqued my curiosity. The assertion is that local variables should be used for computations in a function, not output arguments. It was suggested this would allow the compiler to make additional optimizations otherwise not possible. So, writing a simple bit of code for the example Foo class and compiling the code fragments with g++ v4.4 and -O2 gave some assembler output (use -S). The parts of the assembler listing with just the loop portion shown

What exactly is the difference between My.Computer.FileSystem and System.IO.File

て烟熏妆下的殇ゞ 提交于 2019-12-04 03:17:02
There is a lot of duplication of functions in the My.Computer.FileSystem and System.IO.File namespaces. So what exactly is the difference between: My.Computer.FileSystem.CopyFile(source, dest, True) and: System.IO.File.Copy(source, dest, True) Is there a performance difference? What is everyone's opinion on which which has the edge on read-ability? I personally use the My.Computer Namespace but that is just habit now. My.* is simply a set of facade-pattern classes implemented for VB.NET that encompass common System.IO* (and other) operations. There is a very tiny performance hit since you're

Pimp my LINQ: a learning exercise based upon another post

半世苍凉 提交于 2019-12-04 03:11:16
I decided to try out LINQ for the first time to try and solve this question . The results of my first foray into the wonderful world of LINQ looked like this: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { List<string> list = new List<string>() { "fred-064528-NEEDED1", "xxxx", "frederic-84728957-NEEDED2", "sam-028-NEEDED3", "-----", "another-test" }; var result = from s in list where (from c in s where c == '-' select c).Count() == 2 select s.Substring(s.LastIndexOf("-") + 1

good c style when checking lots of return values

一曲冷凌霜 提交于 2019-12-04 03:05:50
问题 Sometimes I have to write code that alternates between doing things and checking for error conditions (e.g., call a library function, check its return value, keep going). This often leads to long runs where the actual work is happening in the conditions of if statements, like if(! (data = (big_struct *) malloc(sizeof(*data)))){ //report allocation error } else if(init_big_struct(data)){ //handle initialization error } else ... How do you guys write this kind of code? I've checked a few style

Apply Different Style to Button When Pressed

↘锁芯ラ 提交于 2019-12-04 03:03:53
Is there a way to apply a style to a button when the button is pressed? If I have a style in style.xml : <resources> <style name="test"> <item name="android:textStyle">bold</item> </style> </resources> a selector in button.xml : <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/test_pressed" style="@style/test" android:state_pressed="true"/> <item android:drawable="@drawable/test_focused" android:state_focused="true"/> <item android:drawable="@drawable/test_normal"/> </selector> then how would I reference button.xml in my layout? <Button ..