shorthand Questions
6
Solved
Is there any shorthand in c# now that will cutdown the following code:
var testVar1 = checkObject();
if (testVar1 != null)
{
testVar2 = testVar1;
}
In this situation only want to assign testVar...
Skepticism asked 6/6, 2019 at 21:58
11
Solved
So I'm using a shorthand JavaScript if/else statement (I read somewhere they're called Ternary statements?)
this.dragHandle.hasClass('handle-low') ? direction = "left" : direction = "...
Sculpin asked 19/7, 2012 at 5:32
5
Solved
What's the best, preferred way of writing if shorthand one-liner such as:
expression ? $foo : $bar
Plot twist: I need to echo $foo or echo $bar. Any crazy tricks? :)
Jerz asked 27/11, 2013 at 3:13
13
Solved
Is there an easy way to create a multiline string literal in C#?
Here's what I have now:
string query = "SELECT foo, bar"
+ " FROM table"
+ " WHERE id = 42";
I know PHP has
<<<BLOCK
...
6
Solved
In JavaScript ES6 we can create objects where variable names become keys like this:
> let a = 'aaa'
'aaa'
> let b = 'bbb'
'bbb'
> { a, b }
{ a:"aaa", b:"bbb" }
Does Ruby have somethin...
Mozellamozelle asked 21/5, 2016 at 16:22
6
Solved
Just as you can convert the following:
var t;
if(foo == "bar") {
t = "a";
} else {
t = "b";
}
into:
t = foo == "bar" ? "a" : "b";
, I was wondering if there is a shorthand / oneline way to ...
Heres asked 26/2, 2011 at 11:15
10
I am trying to round large digits. For instance, if I have this number:
12,645,982
I want to round this number and display it as:
13 mil
Or, if I have this number:
1,345
I want to round it an...
Surat asked 15/10, 2012 at 16:53
6
Solved
How can I flip the value of a boolean variable in javascript, without having to include the variable name twice?
So
foobarthings[foothing][barthing] = !foobarthings[foothing][barthing];
without ...
Passel asked 20/12, 2012 at 13:7
10
Solved
I've been programming in PHP for years now, but I've never learned how to use any shorthand. I come across it from time to time in code and have a hard time reading it, so I'd like to learn the dif...
3
Solved
Is there a shorthand for this:
bool b = (x > 0) && (x < 5);
Something like:
bool b = 0 < x < 5;
In C#?
Softball asked 9/6, 2016 at 9:18
2
Solved
I am aware of the shorthand for map that looks like:
[1, 2, 3, 4].map(&:to_s)
> ["1", "2", "3", "4"]
I was told this is shorthand for:
[1, 2, 3, 4].map{|i| i.to_s}
This makes perfect s...
Unlace asked 9/1, 2012 at 18:55
7
Solved
I have a deeply nested dictionary in python thats taking up a lot of room. Is there a way to abbreviate something like this
master_dictionary['sub_categories'][sub_cat_name]['attributes'][attribu...
Infiltration asked 24/4, 2018 at 21:39
2
Solved
I want to compare the same variable (or expression) with many different values, and return a different value depending on which value it equals to. I want to do this inline or shorthand, as is poss...
Thomson asked 26/9, 2014 at 14:45
7
Solved
I can't seem to find the correct syntax for the CSS transition shorthand with multiple properties. This doesn't do anything:
.element {
-webkit-transition: height .5s, opacity .5s .5s;
-moz-tran...
Lanctot asked 12/3, 2012 at 15:37
7
the code is
for(int i = 0; i < max; i++) {
//do something
}
I use this exact code many times when I program, always starting at 0 and using the interval i++. There is really only one vari...
4
Solved
I have a variable and if that variable is a object I would like to call a method on that object, if not I want to do nothing.
I'm wondering if there is any reason why I shouldn't do it like this.
...
Nadabas asked 28/7, 2016 at 18:33
7
Solved
I'm wondering if there's a shorter way to write this:
var x = 1;
if(y != undefined) x = y;
I initially tried x = y || 1, but that didn't work. What's the correct way to go about this?
Muttra asked 25/3, 2012 at 22:24
6
Solved
There are two types of if statements in java - classic: if {} else {} and shorthand: exp ? value1 : value2. Is one faster than the other or are they the same?
statement:
int x;
if (expression) {
...
Heinz asked 16/1, 2011 at 16:57
8
Solved
Can I write the if else shorthand without the else?
var x=1;
x==2 ? dosomething() : doNothingButContinueCode();
I've noticed putting null for the else works (but I have no idea why or if that...
Patent asked 17/6, 2012 at 6:0
3
Solved
ES6 introduced a shorthand notation to initialize objects with functions and properties.
// ES6 shorthand notation
const obj1 = {
a(b) {
console.log("ES6: obj1");
}
};
// ES5
var o...
Tachograph asked 16/12, 2016 at 22:8
8
Solved
Is the following shorthand for $(document).ready?
(function($){
//some code
})(jQuery);
I see this pattern used a lot, but I'm unable to find any reference to it. If it is shorthand for $(docu...
Balsamiferous asked 14/5, 2011 at 18:57
6
Solved
When someone writes "nit: removed whitespace" on a commit, what does "nit" mean? I've also seen it capitalized as if it were an abbreviation (i.e. NIT). For an example usage see this post:...
Deonnadeonne asked 7/1, 2015 at 2:23
7
Solved
Does anyone know if there is a way to use some kind shorthand in swift? more specifically, leaving out the braces in things like IF statements... eg
if num == 0
// Do something
instead of
if ...
9
Solved
I have this code in a function, and want to shorten it - it applies the same style to every item in an array.
document.getElementById(divsArray[0]).style.visibility = 'hidden';
document.getElement...
Trinh asked 18/8, 2010 at 15:6
1
Solved
Please help me to find out why an arithmetic operation in CSS variable breaks the code.
I began with a simple CSS file with one rule:
html {
font: 16px/32px Arial;
}
In browsers, it works as w...
Enswathe asked 20/10, 2017 at 14:7
1 Next >
© 2022 - 2024 — McMap. All rights reserved.