question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CC0013 CC0014 ternary operator - not always desired

See original GitHub issue

In some cases, switching to a ternary operator is not a good suggestion. Say, I have this code:

If String.IsNullOrWhiteSpace(path) Or Not File.Exists(path) Then
	skinStream = Application.GetResourceStream(New Uri(DefaultSkinUri)).Stream
Else
	skinStream = File.OpenRead(path)
End If

Changing it to an If() function would yield an immense statement, which is hard to read and to debug. Maybe, Code Cracker should check for the resulting line length or some other parameter to avoid suggesting things that complicate the code.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
carloscdscommented, Aug 9, 2017

@mc0re Ternary operation is not trivial for many developers, but I don’t believe that is complex to understand 😃

0reactions
paul1956commented, Aug 29, 2017

I run into this issue all the time and I think line length is a reasonable solution. If there is no way to set options I would be happy if it new lime was limited to 80 characters or don’t offer refactoring on lines over 30 characters. If someone doesn’t like it they can make the change manually.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ternary operator is always false
What I am trying to do is if reportParameterArray[P_TARGET] doesn't equal to \0 then it should output the actual value otherwise it prints...
Read more >
ultraThinMaterial doesn't work in ternary operator
I'm trying to make the background of a view use the .ultraThinMaterial property with the following code: .background(!isPlayerOpen ?
Read more >
JavaScript Ternary Operator – Syntax and Example Use ...
The ternary operator is a conditional operator which evaluates either of two expressions – a true expression and a false expression – based...
Read more >
Conditional (ternary) operator - JavaScript - MDN Web Docs
The conditional (ternary) operator is the only JavaScript operator that takes three operands: a condition followed by a question mark (?)
Read more >
What is a ternary operator in programming?
No, the ternary operator only evaluates a single condition. If multiple conditions need to be checked, logical operators (e.g., && and ||) or ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found