NETMF for education, a community effort

I have a question regarding the code. Why do you use the more complex class style


BrainPad.TouchPad.IsPadTouched(BrainPad.TouchPad.Pad.Left);
BrainPad.Buttons.IsButtonPressed(BrainPad.Buttons.Button.Left);

instead of


BrainPad.TouchPad.IsPadTouched(BrainPad.TouchPad.Left);
BrainPad.Buttons.IsButtonPressed(BrainPad.Buttons.Left);

or


BrainPad.TouchPad.IsPadTouched(BrainPad.TouchPad.LeftPad);
BrainPad.Buttons.IsButtonPressed(BrainPad.Buttons.LeftButton);

Too my mind, less complex but more meaningful code is an important objective for the project. If there’s any reason for your version, feel free to teach me! :slight_smile:

@ Gus, since you’re just learning VB.NET I’ll mention the With statement in case you’re not familiar. It is one feature that I would love to see come to C#. The above could be written as…


Public Module Module1

    Sub Main()

        ....

        While (BrainPad.LOOPING)
            With BrainPad
                .TrafficLight.RedLightOn()
                .Wait.Seconds(0.5)
                .TrafficLight.RedLightOff()
                .Wait.Seconds(0.5)
           End With
        End While

    End Sub

End Module

Of course, you could move the With to the top of the Sub and avoid typing “Brainpad” on all the other lines, too. Perhaps this causes more confusion for beginners than its worth but it is one advantage of the language.

@ MrAlex92 - only because it makes easier to use using intellisense. I have actually tried your version first and then changed it.

@ ianlee74 - good idea. I have seen this a long time ago but completely forgot about it.

For code to be even more readable you could use:



Also, your loop statement could be simplified to:

```vb
Do
Loop

Did someone ask for a hot dog piano?

5 Likes

Who doesn’t like a little music whilst they eat?

Really looking forward to the next SDK release so we can all try this at home.

https://www.ghielectronics.com/community/forum/topic?id=19329