Skip to content

Fixed VB code and syntax highlighting #1799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 24, 2017
Merged

Conversation

svick
Copy link
Contributor

@svick svick commented Mar 24, 2017

When reviewing #1796, I noticed that this article used the invalid language identifier vb-c#. I fixed that by changing it to csharp in one case and added a separate VB block in the second, because the code was not valid VB.

While here, I also fixed other invalid VB code.

Copy link
Contributor

@rpetrusha rpetrusha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for noticing the rather bizarre language identifier, @svick. Eventually, we're planning to break this up into standalone C# and VB topics, so could you especially add the separate C# and VB code blocks for PropertyChanged?.Invoke(e)? Thanks.

```

The last example demonstrates that the null-condition operators are short-circuiting. If one operation in a chain of conditional member access and index operation returns null, then the rest of the chain’s execution stops. Other operations with lower precedence in the expression continue. For example, `E` in the following always executes, and the `??` and `==` operations execute.

```vb-c#
```csharp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@svick Can you add semicolons at the ends of the lines of C# code?

Copy link
Contributor Author

@svick svick Mar 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are not valid C# statements, so semicolons don't make sense here. I think they are just supposed to be two separate expressions.

Do you think it would be clearer if they were expanded to statements? Something like:

var maybeE = A?.B?.C?[0] ?? E;
var equalsE = A?.B?.C?[0] == E;

@@ -57,21 +59,18 @@ A?.B?.C?[0] == E
var handler = this.PropertyChanged;
if (handler != null)
handler(…)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handler(...);

```

The new way is much simpler:

```vb-c#
```csharp
PropertyChanged?.Invoke(e)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you break this out into two separate code blocks (even though they're basically identical)?

PropertyChanged?.Invoke(e);
PropertyChanged?.Invoke(e)

PropertyChanged?.Invoke(e)

```

The new way is thread-safe because the compiler generates code to evaluate `PropertyChanged` one time only, keeping the result in temporary variable.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a temporary variable

Copy link
Contributor Author

@svick svick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rpetrusha Addressed your comments, except the one where I commented.

```

The last example demonstrates that the null-condition operators are short-circuiting. If one operation in a chain of conditional member access and index operation returns null, then the rest of the chain’s execution stops. Other operations with lower precedence in the expression continue. For example, `E` in the following always executes, and the `??` and `==` operations execute.

```vb-c#
```csharp
Copy link
Contributor Author

@svick svick Mar 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are not valid C# statements, so semicolons don't make sense here. I think they are just supposed to be two separate expressions.

Do you think it would be clearer if they were expanded to statements? Something like:

var maybeE = A?.B?.C?[0] ?? E;
var equalsE = A?.B?.C?[0] == E;

Copy link
Contributor

@rpetrusha rpetrusha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making the changes, @svick!

@rpetrusha
Copy link
Contributor

I think that we can leave them.

@rpetrusha rpetrusha merged commit 61a0936 into dotnet:master Mar 24, 2017
@mairaw
Copy link
Contributor

mairaw commented Mar 24, 2017

I noticed this bizarre identifier this morning when I opening issue #1797. It was even on MSDN: https://msdn.microsoft.com/en-us/library/9c7b2c8f-a785-44ca-836c-407bfb6d27f5!

@svick svick deleted the patch-5 branch March 24, 2017 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants