The P programming language
github.com
github.com
Is there a big difference here, or is this basically just an alternative language for that model?
If anything it reads like the restricted form of the actor model produced by using only Erlang's gen_fsm or Akka's FSM mixin.
(to be clear, using a restricted form with more constraints is a great thing - even better here, where one of the domains they're serving seems to be fairly restricted execution environments)
[1]:
> Each operation either updates the local store, sends messages to other machines, or creates new machines.
> In P, a send operation is non-blocking; the message is simply enqueued into the input queue of the target machine.
[2]: https://en.wikipedia.org/wiki/Actor_model#Fundamental_concep...Programming languages rarely get better introductions and early results than that. Props to the Microsoft Research team on this.
Maybe Google as well due to their reluctance to improve NDK beyond being a way to implement Java native methods and port code into Android.
Calling a core language keyword "goto"? They're brave.
And I'm not convinced of the utility of baking their own C-like imperative language when they could have actually used real C. There are already too many C-like languages out there that are just different enough from C to be annoying.
I thought so too, but it makes sense really. State machine only have one state and can only go to a new state from another - you don't call functions and return to the current state.
Sounds like a dream language :)
It's quite common in low-level code where you want to do a bunch of things that can all fail, and you need to rewind and undo the things that succeeded up to the point of failure.
See http://stackoverflow.com/questions/13001067/why-do-some-kern... and https://www.kernel.org/doc/Documentation/CodingStyle (chapter 7 but that's raw text so I can't link).
#define HANDLE_ERROR(label) bool label = false; #define ENSURE(label, pred) if (!(pred)) { label = true; goto label; } #define RESOLVE(label) label: if (label)
HANDLE_ERROR statements go at the beginning of the block, RESOLVEs go at the end, in the reverse order to the ENSUREs, which go wherever they're required.
It's been working well for me so far.
#define HANDLE_ERROR(label) bool label = false;
#define ENSURE(label, pred) if (!(pred)) { label = true; goto label; }
#define RESOLVE(label) label: if (label)The OP mentioned "previously gained value instantly disappears". I do not see what exactly disappears with GOTO?
I'm not advocating to replace those with gotos btw., except for early jumps to cleanup phases.
To illustrate - which would you prefer:
a = None
try:
a = get_ressource_a()
b = None
try:
b = get_ressource_b(a)
process(a,b)
except BException as e:
handle_errors(e)
finally:
cleanup_b(b)
except AException as e:
handle_errors(e)
finally:
cleanup_a(a)
or a = get_ressource_a()
if not a:
handle_errors()
return
b = get_ressource_b(a)
if not b:
handle_errors()
goto cleanup_a
process(a,b)
cleanup_b:
#do the cleanup
cleanup_a:
#do the cleanup
My dream language would have more or less Python's syntax, with dynamic, inferred, but strong types, no exception handling, and instead Swift's "optional" baked into the language and a very smart logging that I can peak into with the error handler. The error handler could be the only sideeffect allowed when a function is declared pure. I don't need goto if with{} works well with such a system.It provides nearly everything you mention and covers the "finally" case with `defer`. Worth looking at - I re-implemented suckless' slock in Nim[2][3] and it was very pleasant experience.
[1] http://nim-lang.org/
[2] https://klibert.pl/posts/slock_in_nim.html
[3] https://github.com/piotrklibert/nimlockIt's not as nice as F# Type Providers, but it's workable. You could write something similar to Type Providers with macros (given a schema or sample), but I don't know if someone tried this already. With all the standard operators (like property access/assignment and toString equivalent) overloaded to support JSON, it feels quite natural. I wrote a little script consuming a JSON service, it looks like this for example: https://gist.github.com/piotrklibert/b2ba0774244bb7368748a3b...
Nim has its peculiarities and rough edges (it's not even at 1.0 yet), but it's expressive (many of the construct typically built-in in languages are implemented as libraries) and fast. C-level fast, without a huge runtime, so for things like this script it's 4x-16x (IIRC, when reading cached data from disk) faster than compiled F# version (on Mono), for example. My impression of the language is that it's pragmatic and flexible. Also opinionated, which may be both a good and a bad thing, depending on what are your preferences.
> res = res["rates"]["PLN"]
That does look quite reasonable yes. You're right, for a statically typed language it does feels quite dynamic. I think a good blog article comparing Nim to Swift would be very interesting, I couldn't find such a thing.
Thanks for your input!
Edit: Looking at http://roadfiresoftware.com/2015/10/how-to-parse-json-with-s... I think I'd much rather have Nim. This is exactly the sort of thing where types get in the way and slow development down tremendously. If I get external data it should be enough to just be aware that all accesses return an "optional", which has to be dealt with accordingly as part of error handling. Letting types get in the way as well is basically doing the work twice.
The reason its harder to debug is because its harder to visualize/understand.
On the other hand, I think I only used goto once in production in my career (to get out of a double nested loop). And it had a bug.
/s
This is more or less the only time I would use a goto over similar constructions like switch/case or continue/break.
I, N, O, and V are still available. H, T, and W can probably be overwritten without hurting anybody. http://beza1e1.tuxen.de/one_letter_proglangs.html
But having a programming language named Ä seems worth the effort. :-)
https://en.wikipedia.org/wiki/S_(programming_language) (Not really sure how you'd search for this language in particular, though...)
"PlanG offers a system to infuse and promote social impact within brands and develop loyalty through emotional connections with customers."
And the USB driver stack implementation is same for both Windows 8 & and Windows 10, so the answer to your question is - yes.
"Not only can a P program be compiled into executable code, but it can also be validated using systematic testing. P has been used to implement and validate the USB device driver stack that ships with Microsoft Windows 8 and Windows Phone. "
That indicates they modeled it in P with their tool compiling the P specs into some executable. The individual functions the state machine calls would be other C or assembly functions. Microsoft as tools like VCC, Verifast, SLAM, etc to verify C in drivers. I'm curious what combo of them they used on it if any.
Directly using the code would be a huge achievement and can help to avoid a lot of issues that will come with reimplementing it. However it has also quite huge requirements for the code generation. E.g. the scheduler must fit the target system and must be performant for the use-case, the infinite-queue semantics that the state machines seem to have are not ideal for a constrained environment and of course there's questions regarding memory allocation and garbage collection (which should mostly be avoided in drivers).
I think it would be nice to drop the braces entirely. They seem to only function as decoration. Also I would really miss ++, P has many convenience methods including += but no ++.
States & Events provide a right model for async programs. SCXML [0] provides some additional tools for creating abstract finite state machines.
https://www.microsoft.com/en-us/research/wp-content/uploads/...
"Nick, you aren't weirded out by people sneaking a peek?"
"Nah, my protocol is different. It recognizes root cause is them looking at what they don't need to. If I notice this, I'll simply remind them they should turn away from me before I turn something toward them. Not my eyes either. Most rational and irrational people will avoid that outcome to maintain what dignity they can when exiting a bathroom."
The guys got a kick out of that solution but chose not to upgrade their protocol. Their loss. ;)
Edit: https://github.com/p-org/P/wiki/Creating-a-P-Program indicates it compiles to C code.