News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Falling in love with C

Started by shantanu@india, Dec 22, 2022, 07:38 AM

Previous topic - Next topic

Gabi

How I see it:

// the 'For' syntax:
for (initialization; Conditional; increment-decrement){}

then simplify the conditional so it does not look 'scary'

// Conditional (variables A,B,C,Conditional defined as type boolean)
bool A = j < 1 // will result in boolean 0 or 1
bool B = ((grain[i].x / 256) != (grain[j].x / 256)) // will result in boolean 0 or 1
bool C = ((grain[i].y / 256) != (grain[j].y / 256)) // will result in boolean 0 or 1

bool Conditional = A && B || C  // will result in boolean 0 or 1, so False or True

and now, it might be readable:

// simplified, the 'for' loop example above becomes
// which will execute the 'code' inside it while Conditional = True
for(j=0; Conditional ; j++){
// code
}



GL & 73
YO4WM

keytapper

I think that it should be obvious to put the Conditional inside the loop, in order to have the expected comparison.
Ignorance comes with a cost

Gabi

Quote from: keytapper on Dec 27, 2022, 03:35 PMI think that it should be obvious to put the Conditional inside the loop, in order to have the expected comparison.

That is why C seems difficult to understand for some people.
Stick with what you feel comfortable @keytapper  :) 
GL & 73
YO4WM

JonW

#23
Quote from: top204 on Dec 24, 2022, 06:25 PMfor(j = 0; (j < i) && (((grain.x / 256) != (grain[j].x / 256))
                    || ((grain.y / 256) != (grain[j].y / 256))); j++);


Sounds like Boris Johnson  :P   If your not confused and think you may be confused then you are definitely not thinking that you are confused

This is one of the reasons why I don't use C and on the rare occasion i do use it I always break it down into easy flowing code, imagine coming back to code written like that after a few years, you would think what was  I thinking!!.  I find lots of C code is written like a really complex books where the author seems compelled to go back to first principles and waffle for dozens of pages rather than be concise, to the point and explain it as it should be and hence why many technical books are a waste of time and money as they are written by academics, for academics to somehow prove that they are worthy.






Yves

For I = 1 to 10 step 2
Blabalabla....
Next

Seems far more elegant and easy to understand. no ++ {} code, Boolean.
but if you like things that looks complicated and hard to understand at glance go for it.

Yves
Yves

keytapper

Quote from: Gabi on Dec 27, 2022, 04:11 PMThat is why C seems difficult to understand for some people.
Now I grasped what it's the jargon of that programming style. I prefer to use a less complex style.
I wonder sometimes when I read my sources. There are things that are easy at the time are fresh in the mind, but later they tend to be difficult to decipher.
Ignorance comes with a cost

top204

#26
My take on that silly loop mechanism was:

    Dim j As Byte
    Dim i As Byte
    Dim wX_Grain[20] As Word
    Dim wY_Grain[20] As Word

    For i = 0 To Bound(wX_Grain)
        For j = 0 To i
            If (wX_Grain[i] / 256) = (wX_Grain[j] / 256) Then Break
            If (wY_Grain[i] / 256) = (wY_Grain[j] / 256) Then Break
        Next
    Next

I never did work out what the loop did exactly, but it seemed to work. :-)

The "/ 256" is a clumsy way of looking at the high byte of the word array elements, so a more compact and faster code is:
    Dim j As Byte
    Dim i As Byte

    Dim wX_Grain[20] As Word
    Dim wY_Grain[20] As Word
    Dim wTempXY1 As Word
    Dim wTempXY2 As Word

    For i = 0 To Bound(wX_Grain)
        For j = 0 To i
            wTempXY1 = wX_Grain[i]
            wTempXY2 = wX_Grain[j]
            If wTempXY1.HighByte = wTempXY2.HighByte Then Break
            wTempXY1 = wY_Grain[i]
            wTempXY2 = wY_Grain[j]
            If wTempXY1.HighByte = wTempXY2.HighByte Then Break
        Next
    Next

The code was for a sand moving program on a dot matrix LED display, but I never quite found the time to finish it as a working project, and got some of it working. It needed so much of the other nonsense in the C++ code altered. I got some parts of it working, but other parts also needed making into "correct" code so I could follow it more precisely, and actually see what it was doing so I could create code of my own based upon its algorithm. This is the big problem with a lot of C, and especially C++, codes. Where the mis-managed and over complex code listing itself stops a straightforward algorithm being understood. And that's from someone who has written C and C++ code for over 20 years, and it still confuses me sometimes!!! :-)

Amateurtje

ESP32 can be done in B4R for the basic people.. I programmed a ESP8266 with it and made some android apps (B4A)...specially for the B4A the code is sometimes difficult to follow and the forum is not as friendly as here  ;D  ;D  ;D

I wanted to buid a android app and I just have difficulty to follow any C language.... Therefore I went to B4X but....

shantanu@india

Quote from: Amateurtje on Dec 29, 2022, 10:18 AMESP32 can be done in B4R for the basic people.. I programmed a ESP8266 with it and made some android apps (B4A)...specially for the B4A the code is sometimes difficult to follow and the forum is not as friendly as here  ;D  ;D  ;D

I wanted to buid a android app and I just have difficulty to follow any C language.... Therefore I went to B4X but....
For Android try Appinventor from MIT
Regards
Shantanu

Wimax

I admit it is my limitation, but C is the only language I have never learned to use, although I have tried.
I have loved basic since I was a kid, I have seen it grow over time, from the old interpreters to modern compilers ( who among you remembers IBM BASICA or GWBASIC on Olivetti machines ?) I have enjoyed Visual Basic, I have used Pascal and learned to appreciate its peculiarities.
I use scientific software like Matlab and Mathematica for work, I have also used the old and glorious DBase 3 and 4 for management applications. As a boy I learned to use the assembler of the legendary 6502 spending sleepless nights with my beloved C64, I used Omicron Basic for the Atari Mega (Motorola 68000), but there is only one language that I just NEVER managed to digest unfortunately...and that is C.
I have tried it, but it always seemed to me unintelligible, with a semi-alien syntax. I bless the day I discovered Positron16 because I have been able to make even complex applications easily and with excellent results, where C always seems to be the only language to use or, even worse, assembler.

okmn

we need a new basic language compiler for ESP series from dear LES!!!

this is a request call!! to LES..

dear Les;

İs it possible to make new basic programming language comppiler  for ESp series MCU for you ?

ken_k

Quote from: Fanie on Dec 23, 2022, 08:49 AMI'm so glad this thread started...
IMO the problem is not the semicolons at the end of each instruction/command line, but rather a lack of a proper IDE.
I'm attempting to write code for an app for the ESP32-S3, and then there is apparently 3 platforms ? sitting on each other AND you have to connect a standard development board via USB and none of the 3 platforms in it's resulting combined IDE seems tp give any proper indication of anything working (or not).

The C or C++ code is not the problem... its the lack of a proper IDE.

I guess we got spoiled with the ease if using proton, what Les did was awesome.
In my case I'm replacing the 18F45k20 with the ESP32-S3 simply because the pic's aren't available for a year, and I refuse to be held hostage by the Wests political attrocities.

If anyone can refer me to a proper IDE for the ESP32-S3 I will be gratefull forever.

Oh !  And you cannot find a simple programmer for the ESP's anywhere either...

Hi Fanie.
Happy New Year.
I spoke to my friends son that worked for Google as a software engineer, he uses platformio.org with VS Code (Microsoft Visual Studio).
I found some links.
https://platformio.org/
https://randomnerdtutorials.com/vs-code-platformio-ide-esp32-esp8266-arduino/

top204

#32
If I find the time to work on an ARM compiler, I am going to create a Positron32 for the ARM Core 0 devices, and upwards. However, time is money, so I cannot create without a roof over our heads or food in our bellys. :-) And R&D does not provide any money. It did for others I worked for and created for, but never for myself. :-(

I have a book on the ARM Core 0 devices and they look rather straightforward, except for the built in commands and functions that the compiler has, and the 32-bit and 64-bit floating point subroutines that I will need to create for them etc...

I have been thinking of using a funding site, but I will need to do a lot of research to find out how to use them and not get ripped off yet again in my life. :-)




Mapo

I'm waiting the link to participate in the crowdfunding,
good job Les

okmn

Quote from: Mapo on Jan 04, 2023, 04:01 PMI'm waiting the link to participate in the crowdfunding,
good job Les

+1

Fanie

Hello guys.  Sorry but I'm not getting around the time.

Some pics are still available - I saw one for ZAR 1500.00.  Makes you sick.  So I made a decision to not use pics any more.

The ESP chip is great.  The problem is the IDE's.  They all seem to have to be installed over or under by yet another someone's piece of rag to patch something up.
My personal opinion is they are all pathetic.

After two weeks of trying to get a properly working IDE for the ESP I can tell you there is not one (found yet).
The Arduino is probably the worst.  The same code in two windows and the one gives a compile error and the other pass.  The uploaded code in the ESP does not do what it is supposed to do either.
Probably because of all the raggs of code there could be some overlaps and this have weird results.

So regarding the IDEs for the ESP, I would say it is the land rovers of ESP's.  You never know if it is going to work.  Or not.
And I was told by someone, if you don't like the way it works, write the code yourself.  Almost like the landy is leaking oil, and if you don't like it, build your own car.
That same someone takes weeks to complete code which I can do with the Proton IDE in 3 days ;-)

With that I guess Les isn'nt going to adapt the IDE for the ESP (crying smiley)or he would have commented on it.  It's true that communism makes people stupid, and the West is currently off the scale. And the illegal British colony of Sick Africa is not fit for human life any more.  Like Trump said, it's a sh4t hole, and getting worse, just the way the joos like it...

Pics are unavailable apparently for a year... IF they will become available again, I doubt it.

Cheers !

shantanu@india

Fanie,
Forget Arduino.... use Thonny with micropython for ESP.
Writing code is a cakewalk.
Regards
Shantanu

Dompie

Or use ANNEX for ESB32 and ESP8266.
Forum  : Forum link
ESP8266: ESP8266 Help
ESP32  : ESP32 Help

Johan

CPR

Quote from: shantanu@india on Jan 28, 2023, 01:18 PMFanie,
Forget Arduino.... use Thonny with micropython for ESP.
Writing code is a cakewalk.

MicroPython runs interpreted. That's *not* the best choice for anything embedded. Python itself (imho) is an abomination, a truly utterly horrible invention. But if it's an easy fix & it works ok for you with the results you want, then hey :-) Just take the effort to learn C++ it'll pay off.

ken_k