Initialize class fields in constructor or at declaration?

Initialize class fields in constructor or at declaration?

I've been programming in C# and Java recently and I am curious where the best place is to initialize my class fields.Should I do it at declaration?:public class Dice{ private int topFace = 1; private Random myRand = new Random(); p

htaccess redirect to https://www

htaccess redirect to https://www

I have the following htaccess code:RewriteEngine OnRewriteCond !{HTTPS} offRewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]RewriteCond %{HTTP_HOST} !^www\.RewriteRule ^(.*)$ https://www.%{HTTP_HOST

Is there a performance difference between i++ and ++i in C++?

Is there a performance difference between i++ and ++i in C++?

We have the question is there a performance difference between i++ and ++i in C?What's the answer for C++? 1:[Executive Summary: Use ++i if you don't have a specific reason to use i++.]For C++, the answer is a bit more complicated.If i i

Get escaped URL parameter

Get escaped URL parameter

I'm looking for a jQuery plugin that can get URL parameters, and support this search string without outputting the JavaScript error: "malformed URI sequence". If there isn't a jQuery plugin that supports this, I need to know how to modify i

What is the difference between ++i and i++?

What is the difference between ++i and i++?

In C, what is the difference between using ++i and i++, and which should be used in the incrementation block of a for loop? 1:++i will increment the value of i, and then return the incremented value. i = 1; j = ++i; (i is 2, j is 2)i++ w

How to center an element horizontally and vertically?

How to center an element horizontally and vertically?

I am trying to center my tabs content vertically but when I add the css style display:inline-flex, horizontal text-align disappears.How can I make both text alignments x and y for each of my tabs?* { box-sizing:border-box; }#leftFrame { ba

Can I avoid running junit tests twice in eclipse when using a TestSuite?

Can I avoid running junit tests twice in eclipse when using a TestSuite?

I need to do some per-suite initialisation (starting a web-server). It is working fine except that when I run all tests in my project in eclipse my tests run twice. My test suite looks a bit like this:@RunWith(Suite.class)@Suite.SuiteClasse

Does java have an equivalent to the C# “using” clause

Does java have an equivalent to the C# “using” clause

I've seen reference in some C# posted questions to a "using" clause.Does java have the equivalent? 1:Yes. Java 1.7 introduced the try-with-resources construct allowing you to write:try(InputStream is1 = new FileInputStream("/tmp/foo");

When would JavaScript == make more sense than ===?

When would JavaScript == make more sense than ===?

As Which equals operator (== vs ===) should be used in JavaScript comparisons? indicates they are basically identical except '===' also ensures type equality and hence '==' might perform type conversion. In Douglas Crockford's JavaScript: T

Faster 16bit multiplication algorithm for 8-bit MCU

Faster 16bit multiplication algorithm for 8-bit MCU

I'm searching for an algorithm to multiply two integer numbers that is better than the one below. Do you have a good idea about that? (The MCU - AT Tiny 84/85 or similar - where this code runs has no mul/div operator)uint16_t umul16_(uint16

How can I scp a file with a colon in the file name?

How can I scp a file with a colon in the file name?

I'm trying to copy a file using scp in bash with a colon (:) character in the source filename. The obfuscated version of my command I'm using is:scp file\:\ name.mp4 [email protected]:"/path/to/dest"I get this error:ssh: Could not resolve hostname

Array declaration and initialization in Java. Arrays behave differently, when the position of their

Array declaration and initialization in Java. Arrays behave differently, when the position of their

The following is the obvious and usual array declaration and initialization in Java.int r[], s[]; //A very similar case behaves differently, when the position of [] is changed in the declaration statement like as shown below.int []p,

how to verify a method of a non-mock object is called?

how to verify a method of a non-mock object is called?

It seems mockito only verify whether a method of a mock object is called and the mock object always have sth. like doReturn().when(mock object)...But can I creat a mock object and define doReturn().when(mock object)..and then verify a metho

Is it possible to programmatically detect the caret position within a  element?

Is it possible to programmatically detect the caret position within a element?

Assuming a regular text-box with data in it. Is it possible to detect (via JavaScript) the position of the text-coursor inside that text-box? I am able to detect an ARROW LEFT or ARROW RIGHT keydown event - but how to detect the cursor l

Conversion of SVG into PNG/JPEG/BMP and Vice Versa?

Conversion of SVG into PNG/JPEG/BMP and Vice Versa?

Code in PHP to convert SVG into Other Image Formats and opposite?? 1:Well, you'll probably want to use the ImageMagick or GD functions. But be aware that you can't convert from PNG/JPEG/BMP to SVG, that's a one-way street.Edit: Elaborati

wait to load angularjs directive template

wait to load angularjs directive template

What I am trying to do is postpone loading the angular js template for a directive until I really need it. I might not even need it at all. Is there a way that I can maybe only load the template for a directive if I need it. Would a servic

Type definition with a trait: Differences of specifying an explicit lifetime bound?

Type definition with a trait: Differences of specifying an explicit lifetime bound?

I'm having issues understanding the lifetime bound requirements when I use a trait in a type definition. For instance:trait Kind { /* ... */ }type CollectionOfKind = Vec;// => error: explicit lifetime bound requiredThe requirement for lifet

Too long paths because of nested node dependencies

Too long paths because of nested node dependencies

I'm using npm to install dependencies. After I have installed those, I want to share my project with someone who is not technical, and doesn't have npm, so I want to ship the node_modules inside the app.However, because node nests the depen

How to map RuntimeExceptions in Java streams to “recover” from invalid stream elements

How to map RuntimeExceptions in Java streams to “recover” from invalid stream elements

Imagine I'm building a library, that will receive a Stream of Integers, and all the library code needs to do is return a stream of Strings with the string representation of the number.public Stream convertToString(Stream input) { return in

How to properly highlight points in ggplot2 plots that use facets

How to properly highlight points in ggplot2 plots that use facets

In the following example I create two series of points and plot them using ggplot2. I also highlight several points based on their valueslibrary(ggplot2)x And here is the resultNow I want to separate the two cases into two facets, keeping t

Move 0's to end of array

Move 0's to end of array

I need to move all 0's in an array to the end of the array.Example: [1, 10, 0, 5, 7] should result in [1, 10, 5, 7, 0].I am open to doing a reverse loop or a regular loop. I cannot create a new array.Here is what I have so far: for(int i=

What is my current desktop environment?

What is my current desktop environment?

How can I get to know what my desktop environment is using Python? I like the result to be gnome or KDE or else. 1:Tested in Ubuntu 9.10:>>> import os>>> os.environ.get('DESKTOP_SESSION')'gnome'Edit: As mentioned in comments below, this

Parallel query worker thread was involved in a deadlock

Parallel query worker thread was involved in a deadlock

I run an SQL Server Trace to track some deadlocks issues and I was hit on the head with this comment Parallel query worker thread was involved in a deadlock as a reason for the deadlock.Q1: Does this means that the same query is deadlocking

Choose dynamically at runtime which version of a .dll to use

Choose dynamically at runtime which version of a .dll to use

I'm working on a utility for SharePoint. It's an app that works for both SharePoint 2007 and 2010. When I have a reference to the 12.0.0.0 version of the SharePoint.dll, the app works for SharePoint 2007, but not for 2010. If I reference

bridged cast: __bridge_transfer vs __bridge with synthesized setter

bridged cast: __bridge_transfer vs __bridge with synthesized setter

I am using ARC, and have confusion while using __bridge_transfer. I have a property userName as following:@property (nonatomic, retain) NSString *userName;[email protected] userName = _userName;...CASE 1:NSString *name = (__bridge_transfer NSS