In Which @Captain asks C# Beginner Questions
-
@asdf said in In Which @Captain asks C# Beginner Questions:
What's wrong with Resharper?
Crashy Mc Re-Slow-As-Shit-Sharper? Lots of stuff.
In addition to being crashing and slow as shit, the stuff it scribbles over your code windows is ugly as hell. And it's not like Visual Studio is a beautiful application to begin with.
-
@Vaire said in In Which @Captain asks C# Beginner Questions:
@accalia said in In Which @Captain asks C# Beginner Questions:
@Vaire said in In Which @Captain asks C# Beginner Questions:
@accalia said in In Which @Captain asks C# Beginner Questions:
@Vaire said in In Which @Captain asks C# Beginner Questions:
You got resharper on you?
i'v also got sharpie on me.
they make great semi-permanent tattoos.
I would be willing to ignore your use of resharper in exchange for a pony-tat
which pony?
Twilight Sparkle, of course!
-
@Captain said in In Which @Captain asks C# Beginner Questions:
"Comma fixity" is a term I just made up to distinguish between:
Is there a language where there's a difference?
-
@accalia said in In Which @Captain asks C# Beginner Questions:
@Vaire said in In Which @Captain asks C# Beginner Questions:
@accalia said in In Which @Captain asks C# Beginner Questions:
@Vaire said in In Which @Captain asks C# Beginner Questions:
@accalia said in In Which @Captain asks C# Beginner Questions:
@Vaire said in In Which @Captain asks C# Beginner Questions:
You got resharper on you?
i'v also got sharpie on me.
they make great semi-permanent tattoos.
I would be willing to ignore your use of resharper in exchange for a pony-tat
which pony?
Twilight Sparkle, of course!
-
@Bort Yeah, lots of languages don't accept the comma-prefixed style. JavaScript is the first that comes to mind. I also vaguely remember Perl rejecting it.
-
@Captain I'm not able to reproduce it in jsfiddle.
It shouldn't matter because there isn't a difference in fixity in your examples above. Comma is infix in both. So the problem wouldn't be with "comma fixity", it's with how the language treats whitespace, particularly newlines.
Never used Perl.
-
@Captain said in In Which @Captain asks C# Beginner Questions:
@accalia don't you ever forget to type a comma and then have to go item by item in a long list until you find which item was missing it? Maybe C# has better error reporting that other languages where I've done that, but I've been burned by that kind of thing too many times.
Visual Studio will definitely tell you about it, and what line it's on:
There are red squiggles after three and four.
Error reporting will even show you the lines and that it expects a comma:
-
@Captain said in In Which @Captain asks C# Beginner Questions:
@accalia don't you ever forget to type a comma and then have to go item by item in a long list until you find which item was missing it? Maybe C# has better error reporting that other languages where I've done that, but I've been burned by that kind of thing too many times.
The main languages I frequently work in are C (gcc version ancient) and PHP. Both give good diagnostics on where you did wrong.
-
@Captain I also tried it in Perl 5.22 and can't repro there either.
use strict; use warnings; my @foo = ("a" , "b" , "c"); print $foo[0]; print $foo[1]; print $foo[2];
abc
Also tried it in python 2.7, which as meaningful use of indentation, no repro:
list = [ "a" , "b" , "c"] print list[0:3]
['a', 'b', 'c']
-
@PleegWat said in In Which @Captain asks C# Beginner Questions:
@Captain said in In Which @Captain asks C# Beginner Questions:
@accalia don't you ever forget to type a comma and then have to go item by item in a long list until you find which item was missing it? Maybe C# has better error reporting that other languages where I've done that, but I've been burned by that kind of thing too many times.
The main languages I frequently work in are C (gcc version ancient) and PHP. Both give good diagnostics on where you did wrong.
You mean they output "Not for production usage"
-
@JBert said in In Which @Captain asks C# Beginner Questions:
You mean they output "Not for production usage"
I long for the day we switch away from RHEL5 as a build platform.
-
@PleegWat said in In Which @Captain asks C# Beginner Questions:
RHEL5
I'm glad we don't have to support that anymore. If I still had to write C++98 because the code has to compile with GCC 4.1, I'd probably quit.
-
@asdf I need to get a good feature list for that, might bring some people round. Somehow I've been having trouble finding anything.
(@mods jeff please?)
-
@PleegWat said in In Which @Captain asks C# Beginner Questions:
(@mods jeff please?)
Oops, didn't realize we're in Coding Help here. But neither did anyone else.
-
@Bort said in In Which @Captain asks C# Beginner Questions:
It shouldn't matter because there isn't a difference in fixity in your examples above. Comma is infix in both. So the problem wouldn't be with "comma fixity", it's with how the language treats whitespace, particularly newlines.
ASI is basically cancer. Nevertheless, I've worked with more than a couple FOSS projects now whose code style is that semicolons are forbidden.
Filed under: Typings, Karma, npm...
-
@Captain said in In Which @Captain asks C# Beginner Questions:
@Bort Yeah, lots of languages don't accept the comma-prefixed style. JavaScript is the first that comes to mind. I also vaguely remember Perl rejecting it.
JS is happy with you arranging commas and whitespace however you want. It will barf if you have a trailing comma at the end of the list though, which only reinforces leading commas everywhere for me.
-
@fwd said in In Which @Captain asks C# Beginner Questions:
JS is happy with you arranging commas and whitespace however you want. It will barf if you have a trailing comma at the end of the list though, which only reinforces leading commas everywhere for me.
Afaik they fixed that in ES5. Both of these should work in modern browsers:
({ one: 1 ,two: 2 ,three: 3 , }); [ 1 ,2 ,3 , ];
However, be wary of extra commas;
[1, 2, 3,,].length === 4
because it inserts undefined at [3] .
-
@Vaire said in In Which @Captain asks C# Beginner Questions:
@Captain said in In Which @Captain asks C# Beginner Questions:
@JBert Fixity just means "position of an operator relative to its arguments". So, typical functional notation uses fixity like
f x
to apply the functionf
tox
. "Comma fixity" is a term I just made up to distinguish between:list = [ theFirst, theSecond, theThird ]
and
list = [ theFirst , theSecond , theThird ]
The point being, C# doesn't care which I type. (I prefer the latter notation)
I also prefer that format. I picked it up from SQL stuff.
[waves] Hiiiii @accaliaDitto here!
I use Perl for report munging/slinging etc and Perl allows an array to be initialized from a list like:
my @array = ( 1, 2, 3, 4, )
.
That final , is optional and ignored. Always adding the final comma makes sorting and adding additional items to the list easy-peasy.In SQL doing the column list with the comma first like the second of @Captain's examples keeps me from having the dreaded (to me) "hanging comma" error when I rearrange the comma list because of raisins...
@blakeyrat said in In Which @Captain asks C# Beginner Questions:
@Captain It also doesn't care if you add a trailing comma:
list = [ theFirst, theSecond, theThird, ];
Which is brilliant and every programming language should support it dammit.
-
@fwd said in In Which @Captain asks C# Beginner Questions:
@Captain said in In Which @Captain asks C# Beginner Questions:
@Bort Yeah, lots of languages don't accept the comma-prefixed style. JavaScript is the first that comes to mind. I also vaguely remember Perl rejecting it.
JS is happy with you arranging commas and whitespace however you want.
If only that were true.
What does the following function return?
function foo() { return { foo: true }; }
If you said
undefined
, congratulations, you've probably dealt with JavaScript before. If not, don't worry, ASI has your back and helpfully inserted that semicolon you forgot after that return statement. Also, it was a little weird for you to have a block on the next line containing a goto label and a boolean expression, but we know that was supposed to be a statement. That stray semicolon at the end is fine, too; just an empty statement. JavaScript is a laidback language and won't judge you for your idiosyncrasies.If this behavior seems strange or unexpected, I recommend the book Effective JavaScript to explain everything you assumed you already knew about JavaScript.
-
@fwd said in In Which @Captain asks C# Beginner Questions:
which only reinforces leading commas everywhere for me.
Not before the first item, surely?
-
@error said in In Which @Captain asks C# Beginner Questions:
If this behavior seems strange or unexpected
I'm gonna go with "this behavior is strange and unexpected". Enough so that the fact it's documented doesn't change that
factopinion.
-
@Dreikin said in In Which @Captain asks C# Beginner Questions:
@error said in In Which @Captain asks C# Beginner Questions:
If this behavior seems strange or unexpected
I'm gonna go with "this behavior is strange and unexpected". Enough so that the fact it's documented doesn't change that
factopinion.Here's another fun one, maybe more obvious:
(The comments are explaining the language features used, not the WTF)var foo = 0; // global variable foo // functions can be constructors (i.e. invoked with "new") // there's no way to tell if a function is meant to be a constructor except naming convention function Bar() { // constructor function this.foo = 0; // set property foo } // method declaration Bar.prototype.incrementFoo = function() { this.foo++; }; var bar = new Bar; // instantiate Bar by calling it as a constructor bar.incrementFoo(); var incrementFoo = bar.incrementFoo; incrementFoo(); console.log( 'global foo', foo ); console.log( 'property foo', bar.foo );
So, global foo: 0, property foo: 2? Only to the untrained eye.
Obviously you get global foo: 1, property foo: 1. Because reasons.
In JavaScript, the
this
keyword doesn't work like in any other language (that I'm aware of). It refers to the function's "receiver", which gets bound at time of invocation. When I aliasedincrementFoo
to a variable, I threw away information about the receiver, and instead of having a reference to a method, I now had a function (really, there's no distinction in JS).That's still not really the WTF. The comes in, because JavaScript assumes that, since when I called
incrementFoo
the second time it didn't have a receiver (nothing on the left side of a dot), the receiver should default to the global object (window
, in a browser environment). So, when my "method" referred tothis.foo
, that becamewindow.foo
, which meant the globalfoo
.Also, note that declaring the global
foo
variable with thevar
keyword did not prevent it from becoming a property ofwindow
. I had a coworker once try to declare a globallocation
variable. This, of course, didn't stop it from referring to the built-inwindow.location
property. He was very confused that whenever he assigned to it, the browser would navigate away from his webpage.So, don't use global variables (except the language can trick you into doing so when you don't realize it).
-
@error Why are you posting this stuff in the "captain asks C# questions" topic?
-
@blakeyrat JavaScript was mentioned, and then ASI, which led to the topic of JavaScript WTFs (of which ASI is one of many).
It's less off-topic than most threads on the site, and actually about code WTFs (unlike most of them).
-
@error it's still dwarfing the actual subject in a thread where someone needs help, with massive detailed descriptions of things no one cares about but you.
-
@Magus said in In Which @Captain asks C# Beginner Questions:
@error it's still dwarfing the actual subject in a thread where someone needs help, with massive detailed descriptions of things no one cares about but you.
I care about JS ... deeply ... in the same sense that I care about a roach infestation, and want to kill it with fire. Does that count?
-
@error said in In Which @Captain asks C# Beginner Questions:
It's less off-topic than most threads on the site
Yeah, but the help section is meant to be the most on-topic section, so people can get actual answers.
-
@blakeyrat said in In Which @Captain asks C# Beginner Questions:
@Captain It also doesn't care if you add a trailing comma:
Which is brilliant and every programming language should support it dammit.I wish languages didn't care about leading commas either....
Then I can do silly stuff like comment out the first item for a test run and not have to fix the commas every time.list = [//theZeroth , theFirst , theSecond , theThird ];
-
@darkmatter I agree completely. I should be able to sort a list of elements (on screen, in the file, etc) without having to fix syntax.
-
and yes I realize if I did it like
list = [//theZeroth, theFirst, theSecond, theThird, ];
then it would work, but only in languages that accept trailing commas.
I'd switch my comma style to always trailing... except that doesn't work in basically every SQL parser, which is 99% of my use of comma lists.
-
@Yamikuronue said in In Which @Captain asks C# Beginner Questions:
@error said in In Which @Captain asks C# Beginner Questions:
It's less off-topic than most threads on the site
Yeah, but the help section is meant to be the most on-topic section, so people can get actual answers.
TBH I barely even notice what section threads are in anymore (not since Community Server). I watch the most recent threads list, which aggregates threads from all sections. I barely glance at the section. Mea culpa.
In my defense, I was the first one to answer the OP with actual help.
-
I'm sure if @Captain really had a problem being buried then flags and jeffed posts could happen. But going by their other help thread devolving into Mafia smacktalk, probably not. :P
-
@error said in In Which @Captain asks C# Beginner Questions:
@fwd said in In Which @Captain asks C# Beginner Questions:
@Captain said in In Which @Captain asks C# Beginner Questions:
@Bort Yeah, lots of languages don't accept the comma-prefixed style. JavaScript is the first that comes to mind. I also vaguely remember Perl rejecting it.
JS is happy with you arranging commas and whitespace however you want.
If only that were true.
What does the following function return?
well, there are no comma separated items, so "irrelevant"?
-
@fwd It was a counter-example showing that JavaScript does not allow you to arrange commas and whitespace however you want. That newline completely changed the meaning of most of the parse tree of that function.
-
@error said in In Which @Captain asks C# Beginner Questions:
@fwd It was a counter-example showing that JavaScript does not allow you to arrange commas and whitespace however you want. That newline completely changed the meaning of most of the parse tree of that function.
If you want to make your point then do it. don't drag my post in and deliberately misread it as an excuse to to so. I didn't say js allows you to do whatever you want with whitespace, I said you can arrange commas and whitespace however you like.
-
@fwd said in In Which @Captain asks C# Beginner Questions:
@error said in In Which @Captain asks C# Beginner Questions:
@fwd It was a counter-example showing that JavaScript does not allow you to arrange commas and whitespace however you want. That newline completely changed the meaning of most of the parse tree of that function.
If you want to make your point then do it. don't drag my post in and deliberately misread it as an excuse to to so. I didn't say js allows you to do whatever you want with whitespace, I said you can arrange commas and whitespace however you like.
You can arrange them however you like, except that rearranging them will semantically change how your code is parsed.
-
@Khudzlin said in In Which @Captain asks C# Beginner Questions:
@fwd said in In Which @Captain asks C# Beginner Questions:
which only reinforces leading commas everywhere for me.
Not before the first item, surely?
no sir, "everywhere" referring to languages I work in being sql, js, and c# when the rest of the team will tolerate it.
-
@error said in In Which @Captain asks C# Beginner Questions:
@fwd said in In Which @Captain asks C# Beginner Questions:
@error said in In Which @Captain asks C# Beginner Questions:
@fwd It was a counter-example showing that JavaScript does not allow you to arrange commas and whitespace however you want. That newline completely changed the meaning of most of the parse tree of that function.
If you want to make your point then do it. don't drag my post in and deliberately misread it as an excuse to to so. I didn't say js allows you to do whatever you want with whitespace, I said you can arrange commas and whitespace however you like.
You can arrange them however you like, except that rearranging them will semantically change how your code is parsed.
show me an example where js falls down parsing something with commas because of whitespace.
-
yeah that'll return undefined, but does the
{ foo:true };
really implement a goto label or just define a random inline object for no reason?
According to chrome console, that simply defines an object with a property foo that is true.
-
@darkmatter That was the understanding I have based on reading Doug Crockford.
{ // start of a block, which JavaScript has (for some reason) even though they don't define a new variable scope or anything logical like that foo: // goto label true // expression parsed as a statement (also valid for some reason) } // end block ; // empty statement
Chrome console:
{ foo: true };
true
(not{ foo: true }
)Edit: note that the whitespace is significant in these examples, which was kind of the whole point I was making.
-
@error said in In Which @Captain asks C# Beginner Questions:
holy balls... it's the ; that buggers that out, regardless of location.... That's completely illogical!{ foo: true }
Object {foo: true}
{ foo: true };
true
edit: i see why part of why I got the object back when not using the semi-colon. Chrome console turns the non-semi-colon version into a parenthetically wrapped version of the command. Odd.
-
@darkmatter said in In Which @Captain asks C# Beginner Questions:
@error said in In Which @Captain asks C# Beginner Questions:
holy balls... it's the ; that buggers that out, regardless of location.... That's completely illogical!Ah, the semicolon, not the whitespace: interesting. It is also interesting that two completely different parse trees can emerge from the same syntax.
-
@error said in In Which @Captain asks C# Beginner Questions:
the semicolon, not the whitespace:
I'm not sure if it's the ASI or Chrome's console implementation.
Because when I use [up] to retrieve last command, it brings back:({ foo: true })
instead of what I keyed in.
-
@darkmatter said in In Which @Captain asks C# Beginner Questions:
@error said in In Which @Captain asks C# Beginner Questions:
the semicolon, not the whitespace:
I'm not sure if it's the ASI or Chrome's console implementation.
Because when I use [up] to retrieve last command, it brings back:({ foo: true })
instead of what I keyed in.
So Chrome has automatic parentheses insertion?
Filed under: Maybe somebody misunderstood when they asked for an API?
-
@darkmatter said in In Which @Captain asks C# Beginner Questions:
instead of what I keyed in.
I bet you it's trying to help you not accidentally make a block with a label.
-
OK, this isn't strictly a C# question, but it's related enough.
How do I start a PowerShell project using VisualStudio 2015?
-
@Captain searching powershell in VS2015 isn't bringing back anything, even from the online template listing.
Not sure what exactly a powershell "project" would mean? Just that you want the project features of the VS IDE?
*clearly I am not experienced enough in powershelling
-
@Captain I know there's a powershell tools extension; might need that. Normally you'd press the windows key and type 'ise' and press enter.
-
@Magus yukk, Microsoft's flagship system utility/scripting language isn't first class in the flagship IDE? I guess we can blame that open sourcer Erik Meijer for writing Monad in the first place.
I'll try ISE but I kind of wanted to use a single editor instead of a bunch of slightly different editors. Especially since I'm slowly trying to learn VS. Vim is the one true editor
@darkmatter said in In Which @Captain asks C# Beginner Questions:
Not sure what exactly a powershell "project" would mean? Just that you want the project features of the VS IDE?
I guess I want to be able to write PowerShell scripts, and have the IDE do all the scaffolding, and have Intellisense for PowerShell functions. Ideally within VS so I don't have to learn yet another shitty Windows text editor. VisualStudio is fairly nice anyway.
-
@Captain Like I said, there's a powershell extension that adds a bunch of stuff.
If you want something more fun, though, you could go to view, other windows, and enable C# interactive. Since C# and F# both have REPLs now :D