Skip to content
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

About ++ or -- operator #72

Open
Whismeril opened this issue Feb 16, 2021 · 3 comments
Open

About ++ or -- operator #72

Whismeril opened this issue Feb 16, 2021 · 3 comments
Labels
help wanted Extra attention is needed

Comments

@Whismeril
Copy link

This code

int i = 0;
//++ or -- onl
i++;
++i;
i--;
--i;

//++ or -- in instruction
DoSomethingWithI(i++);

DoSomethingWithI(++i);

DoSomethingWithI(i--);

DoSomethingWithI(--i);

is converted like this

Private i As Integer = 0
'++ or -- only
i += 1 'perfect
i += 1 'perfect
i -= 1 'perfect
i -= 1 'perfect

'++ or -- in instruction
DoSomethingWithI(Math.Min(Interlocked.Increment(i), i - 1))'makes questions

DoSomethingWithI(Interlocked.Increment(i))

DoSomethingWithI(Math.Max(Interlocked.Decrement(i), i + 1))

DoSomethingWithI(Interlocked.Decrement(i))
  1. Interlocked.Increment(i) should work if System.Threading is imported, conversion doesn't notify that.

  2. In

Math.Min(Interlocked.Increment(i), i - 1)

why first increment and then calcul i - 1 ?

this

Math.Min(i, Interlocked.Increment(i))

does the same with one subtraction less

Math.Min(Interlocked.Increment(i), i - 1)

could be obscure for beginner, convert in 2 lines mays be easier for them

DoSomethingWithI(i++);

goes

DoSomethingWithI(i)
i += 1

and

DoSomethingWithI(++i);

goes

i += 1
DoSomethingWithI(i)
@paul1956
Copy link
Owner

paul1956 commented Feb 16, 2021

@Whismeril Multiline conversions from single line is complex for translator especially if it is in a loop. In SDK style VB projects System is always included. I could use Math.Min(i, Interlocked.Increment(i)), and I might do some testing with it but I also do decrements. It you want to look at the code and do a PR I will review.

paul1956 added a commit that referenced this issue Feb 17, 2021
@paul1956 paul1956 added the help wanted Extra attention is needed label Feb 17, 2021
@paul1956
Copy link
Owner

@Whismeril think about DoSomethingWithI(i++, i--,..); There are way too many places with multiple statements don't work and may not even be possible.

@Whismeril
Copy link
Author

I understand the difficulty to translate one line into two, especially for a loop.
And (i++, i--,..); is an unstoppable argument, I didn't thought about it.

I only code in VB.Net in order to try helping beginners in forums.
I used to says them to search in C# too and convert code.
So when I’ve found you project, couple of days ago, I wanted the test it.
It’s very good, and your reactivity with my issues is to your credit.

But when compiling Visual Studio returns « import missing import » to the line DoSomethingWithI(Math.Min(Interlocked.Increment(i), i - 1)) my first reaction wasn’t looking for the messing assembly, but wondering was is this strange way of coding.
So I suppose beginner could be lost by compiling error in this strange line.
If converter could add Import System.Threading or at least convert like this DoSomethingWithI(Math.Min(System.Threading.Interlocked.Increment(i), i - 1)) no error occurs and beginner could have reflexion on a working line, if he see it.

I tested this case in few online converters, they do the same conversion

paul1956 added a commit that referenced this issue Mar 25, 2021
Change Interlocked.Increment to Threading.Interlocked.Increment to partly address issue #72 and update tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants