Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Bloody
Mar 3, 2013

Mr Dog posted:

The best thing I can say about visual studio is that it isn't terrible I guess.

gotta love c# enums. "Hey let's have a strongly-typed enum facility in our language that actually isn't strongly typed at all fart fart fart fart"

(you can cast arbitrary integers to enum types in c# and they're basically little more than reflective sugar for ints. whereas java treats the possible values of enums as opaque global static instances of that enum type instead. java: doing the poo poo that c# rushed out the door first, properly)

https://www.youtube.com/watch?v=eSMeUPFjQHc

Adbot
ADBOT LOVES YOU

Shaggar
Apr 26, 2006
also casting enums to ints and vice versa in c# is probably based on the int values of the enum values which as you mentioned are secret ints. idr how default values get assigned (by order?) but you can specify them manually.

either way c# enums suck

Bloody
Mar 3, 2013

so maybe don't cast ints to enums tada no more problem

double sulk
Jul 2, 2010


lol i forgot this song/video existed

gonadic io
Feb 16, 2011

>>=
in Haskell enums are implemented in terms of ints and functions to convert back and forth between the enum and the int

code:
data Suit = Hearts | Diamonds | Clubs | Spades
    deriving Enum

-- then these functions all work right out of the gate:
toEnum :: Int -> Suit

fromEnum :: Suit -> Int
    -- Hearts = 0, Diamonds = 1 etc

succ :: Suit -> Suit
    -- succ Hearts = Diamonds

[Diamonds .. Spades]
    -- the list [Diamonds, Clubs, Spades]
idk if you'd consider that good or bad

gonadic io fucked around with this message at 15:52 on Mar 10, 2014

Shaggar
Apr 26, 2006
that's really gross

Shaggar
Apr 26, 2006
Haskell, I mean.

zokie
Feb 13, 2006

Out of many, Sweden
I find C# enums to be pretty sweet, it really just being an int helpful for working together with SQL. Also it allows for bit wise operations for having multiple active values. [FlagsAttribute] owns pretty hard.

Also lol at complaining about enums being syntactic sugar, if you want to be a sperg just use State Pattern.

Shaggar
Apr 26, 2006
java enums do all of that plus you can do more stuff w/ them. their better all around.

qntm
Jun 17, 2009

AlsoD posted:

in Haskell enums are implemented in terms of ints and functions to convert back and forth between the enum and the int

code:
data Suit = Hearts | Diamonds | Clubs | Spades
    deriving Enum

-- then these functions all work right out of the gate:
toEnum :: Int -> Suit

fromEnum :: Suit -> Int
    -- Hearts = 0, Diamonds = 1 etc

succ :: Suit -> Suit
    -- succ Hearts = Diamonds

[Diamonds .. Spades]
    -- the list [Diamonds, Clubs, Spades]
idk if you'd consider that good or bad

I would consider that bad

Cybernetic Vermin
Apr 18, 2005

the p. thoroughly amazing part about the sql connection is how sql databases actually use integers for symbolic enumeration fields, with that amazingly pointless extra table naming each value, and probably a key constraint ensuring that the poo poo query optimizer has an extra way to make things ridiculously slow

Shaggar
Apr 26, 2006
enums and checked exceptions are 2 places where java is undeniably better than c#.

Bloody
Mar 3, 2013

too bad about the everything else

seiken
Feb 7, 2005

hah ha ha

http://www.espruino.com/Performance

just javascript would be bad. espruino's custom javascript implementation is a lot worse than bad

Shaggar
Apr 26, 2006

Bloody posted:

too bad about the everything else

everything else in java is pretty good too

Bloody
Mar 3, 2013

seiken posted:

http://www.espruino.com/Performance

just javascript would be bad. espruino's custom javascript implementation is a lot worse than bad

jesus christ kill all web developers

twenty bytes for a boolean

ive done entire meaningful projects with 20 bytes of ram

what the gently caress.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
i'm just gonna quote the whole thing, it's a cavalcade of comedy

quote:

Performance Notes

Espruino is designed to run on devices with very small amounts of RAM available (down to 8kB). As such, Espruino makes some compromises that affect the performance in ways that you may not expect.

Please Note: It's very easy to use the information below to pick holes in Espruino's implementation - however we have provided it anyway in order to help our users. We suggest that you actually try Espruino before writing it off - you'll find out that in the real world these decisions pay off, and allow us to create a surprisingly capable JavaScript implementation that uses around 1000x less RAM than desktop JavaScript implementations.


Espruino executes code directly from source

So source code size affects code execution speed.

On the Olimexino (a mid-range, 72Mhz device) a simple loop will toggle a pin at around 3kHz using code like this:

while (1) { D14.set();D14.reset(); }

While code like this will toggle a pin at around 2.5kHz.

while (1) { D14.set(); D14.reset(); }

This applies equally to comments - so it pays to keep comments above or below a function declaration, not inside it.

On the plus side, this makes executing code directly from a String very efficient.


Why don't you compile to bytecode or Native code?

It uses too much RAM. To put it in context, look at the square below:






That square (110x110x32bpp) is using as much RAM as Espruino has IN TOTAL. If you want the source code (so you can edit it on the device) then there's not enough room for that, bytecode, AND all the variables you'll want.


Executing code has a noticable overhead - give as much work to Espruino in one go as you can

Many of the IO routines are designed to allow you to send lots of data at once. For instance, instead of:

SPI1.send(1);
SPI1.send(2);
SPI1.send(3);

You can just do:

SPI1.send([1,2,3]);

This will be significantly faster. For maximum speed/efficiency you can put the data in a String (see below).

SPI1.send("123");


Espruino stores arrays and objects in Linked Lists

So the number of elements in an array or object will seriously affect the time it takes to access elements in it. For instance, if you're storing two-dimensional data, it is faster to store data in a two-dimensional array than it is to store it in a single-dimensional array!

As Espruino becomes more mature the Linked Lists may be replaced with a Tree structure, but for now it is very useful to be aware of this limitation.


Every datatype in Espruino is based on a single 20 byte storage unit

This makes allocation and deallocation very fast for Espruino and avoids memory fragmentation. However, if you allocate a single boolean it will still take up 20 bytes of memory.

This may seem inefficient, but if you compare this with a naive malloc/free implementation you'll realise that it saves a significant amount of RAM.

Note: on smaller devices (with less than 256 variables) Espruino uses 16 bytes per storage unit (not 20).


Arrays and Objects use two storage units per element (one for the key, and one for the value).

This means that Sparse Arrays are relatively efficient, but Dense arrays are not. For these you should use Typed Arrays. See below.



Strings or Typed Arrays are the most efficient way to store data

Strings and Typed Arrays use the same storage format, where you get on average 16 bytes of data per 20 byte Storage unit. So for an array of bytes, it's 32 times more efficient to use a String or Typed Array than a normal (sparse) Array. It's also faster too!

You create a Typed Array with a simple command:

a = new Uint8Array(50); // 50 elements
a = new Uint8Array([1,2,3,4,5,6,7,8,9,10]); // 10 elements, pre-set
a = new Int8Array(50);
a = new Int32Array(50);
a = new Float32Array(50);

And then you can access it like a normal Array. The only thing you can't do is change the length dynamically. There are other formats of typed array too - see the Reference

Bloody
Mar 3, 2013

On the Olimexino (a mid-range, 72Mhz device) a simple loop will toggle a pin at around 3kHz using code like this:

while (1) { D14.set();D14.reset(); }

im the twenty-four thousand cycles to do a two-statement while loop all to avoid writing:

while(1)
{
PORTC_OUTTGL = PIN3_bm;
}

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
things they don't understand:
- how an in circuit debugger actually works
- what a map file is
- how even very simple implementations of malloc for embedded environments work
- that being able to toggle a pin at 3 khz in a tight loop on a 72 mhz device is not an accomplishment(!)
- what "the metal" is
- why every single decision they made here was a bad one, even if you accept their flawed premise of programming a microcontroller w/ javascript

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

Bloody posted:

im the twenty-four thousand cycles to do a two-statement while loop all to avoid writing:

while(1)
{
PORTC_OUTTGL = PIN3_bm;
}

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde

Mr Dog posted:

gotta love c# enums. "Hey let's have a strongly-typed enum facility in our language that actually isn't strongly typed at all fart fart fart fart"
do you also complain that your toothbrush doesn't have a huge plug on the end of hte handle to keep you from jamming it down your throat

seiken
Feb 7, 2005

hah ha ha

Otto Skorzeny posted:

i'm just gonna quote the whole thing, it's a cavalcade of comedy

yeah, i was gonna quote some choice bits but then just gave up

Bloody
Mar 3, 2013

i was confused when i noticed that that article was hosted on their own website and not the website of somebody making GBS threads on them for having such hilariously bad ideas

Zaxxon
Feb 14, 2004

Wir Tanzen Mekanik

Otto Skorzeny posted:

i'm just gonna quote the whole thing, it's a cavalcade of comedy

jesus christ that is awful.

Cybernetic Vermin
Apr 18, 2005

tbf tiny tcl-like languages are p. neat in just doing sort of flexible command language pieces of embedded software, since the core of tcl (i.e. the literal "every single operation is a string replacement thing" part) takes a tiny amount of space and is p. decently high-level to work with

asm+tcl is a legit combo, no reason to go to a tcl-style js though

forth is p. still better though

Nomnom Cookie
Aug 30, 2009



Otto Skorzeny posted:

things they don't understand:
- how an in circuit debugger actually works
- what a map file is
- how even very simple implementations of malloc for embedded environments work
- that being able to toggle a pin at 3 khz in a tight loop on a 72 mhz device is not an accomplishment(!)
- what "the metal" is
- why every single decision they made here was a bad one, even if you accept their flawed premise of programming a microcontroller w/ javascript

if you have time it would be cool if you could trash their poo poo in detail cause idk gently caress about embedded but i think its rad

mobby_6kl
Aug 9, 2009

by Fluffdaddy

Gazpacho posted:

do you also complain that your toothbrush doesn't have a huge plug on the end of hte handle to keep you from jamming it down your throat

Seems pretty obvious that enums should be int, how else would you use bitwise operators on them?

Bloody
Mar 3, 2013

Kevin Mitnick P.E. posted:

if you have time it would be cool if you could trash their poo poo in detail cause idk gently caress about embedded but i think its rad

Bloody posted:

On the Olimexino (a mid-range, 72Mhz device) a simple loop will toggle a pin at around 3kHz using code like this:

while (1) { D14.set();D14.reset(); }

im the twenty-four thousand cycles to do a two-statement while loop all to avoid writing:

while(1)
{
PORTC_OUTTGL = PIN3_bm;
}

Sapozhnik
Jan 2, 2005

Nap Ghost
tbf OpenFirmware is basically this idea except done properly, with Forth instead of JS.

Firmware programming in JavaScript is like anything programming in INTERCAL or BrainFuck. It's an entertaining little time-waster but lol @ using it for anything serious (these people are actually doing it unironically though which is just :psyduck: )

Also I think Intel's Galileo board thing isn't much better at GPIO. It has PCIe and XIP SPI and all that fun poo poo but all the GPIOs are broken out on an external I2C mux, I2C being the slowest serial protocol around other than RS232. They're really sweating bullets about x86 not being a growth sector any more huh.

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

why would anyone capable of writing an embedded javascript vm want to seriously write embedded javascript

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

quote:

Espruino executes code directly from source

So source code size affects code execution speed.

On the Olimexino (a mid-range, 72Mhz device) a simple loop will toggle a pin at around 3kHz using code like this:
code:
while (1) { D14.set();D14.reset(); }
While code like this will toggle a pin at around 2.5kHz.
code:
while (1) { D14.set();                 D14.reset();               }

:catstare:

emoji
Jun 4, 2004

HORATIO HORNBLOWER posted:

that's very much "in production" even if the audience is internal rather than external. if your external product deserves to be written in a real language and with a maintainable process then your internal product does too. there's no excuse for using this poo poo anywhere except for utter laziness and a complete lack of care. if you're moving on to the next thing in a year and you feel nothing but spite for your fellow man who will have to deal with this garbage after you're gone go right ahead. but don't pretend it's ok because it's "just" part of your build process, as if that were something minor and inconsequential.

lol u mad. you know there are people who make more than you do writing javascript also

prefect
Sep 11, 2001

No one, Woodhouse.
No one.




Dead Man’s Band

Otto Skorzeny posted:

i'm just gonna quote the whole thing, it's a cavalcade of comedy

quote:

...So source code size affects code execution speed....

does that include whitespace?

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

prefect posted:

does that include whitespace?

quote:

On the Olimexino (a mid-range, 72Mhz device) a simple loop will toggle a pin at around 3kHz using code like this:
code:
while (1) { D14.set();D14.reset(); }
While code like this will toggle a pin at around 2.5kHz.
code:
while (1) { D14.set();                 D14.reset();               }

prefect
Sep 11, 2001

No one, Woodhouse.
No one.




Dead Man’s Band
what does it mean to "toggle a pin", anyway? (yes i am dumb)

Cybernetic Vermin
Apr 18, 2005

actual pin on the chip going high/low

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

prefect posted:

what does it mean to "toggle a pin", anyway? (yes i am dumb)

set it high then set it low repeatedly such that the output looks like a square wave

Bloody
Mar 3, 2013

it means change the pin from its current state to its other possible state

kitten emergency
Jan 13, 2008

get meow this wack-ass crystal prison
holy poo poo that espruino thing makes me literally irl mad at the world

Adbot
ADBOT LOVES YOU

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde
our runtime performance is lovely. on the plus side, it's consistently lovely!

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply