|
This brings to mind pre-processor games that attempted to make C more "Pascal-like" by replacing '{' with 'begin', '}' with 'end', etc. This is of limited utility, and only confuses those who expect to see native C# code.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
#define while if
#define true ((__LINE__&31)!=31)
Always fun to work with ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Who in their right mind would ever let you loose with a preprocessor?
Real programmers use butterflies
|
|
|
|
|
What's the problem? It's true most of the time ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I mean, wouldn't it just be simpler to pour a sticky beverage on your CPU?
Real programmers use butterflies
|
|
|
|
|
Ah, but sticky liquids don't change the results when you start adding debug code ... :EvilGrinSmiley:
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
In that case, run one of your DRAM sticks over your cat in a dry climate. That should do the trick.
Real programmers use butterflies
|
|
|
|
|
If you have a rope you can hang yourself, it doesn't mean you should.
I'm not sure how many cookies it makes to be happy, but so far it's not 27.
JaxCoder.com
|
|
|
|
|
They should revoke your coding license.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
This must be a usage of 'fun' specific to Wales.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
I was recently porting C# code to C. I did several times for recent projects. It's because I have years of C# code I'm not actively using but I'm currently developing stuff in C++ and sometimes C
Real programmers use butterflies
|
|
|
|
|
Quote: I've been porting large chunks of C code to C#.
So next you will have to use something like Clang bindings for .NET and Mono written in C# to get it back up to speed
Seriously: did you consider using P/Invoke?
Espen Harlinn
Senior Architect - Ulriken Consulting AS
The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague.Edsger W.Dijkstra
|
|
|
|
|
If you don't mind changing the case, just add:
using static System.Math; to the top of your code file.
using static System.Math;
...
double cosX = Cos(x);
double cosY = Cos(y); using static directive - C# Reference | Microsoft Docs[^]
Otherwise, a static (and possibly local) function would have better performance.
private static double cos(double radians) => Math.Cos(radians);
private void Foo(double x, double y)
{
double cosX = cos(x);
double cosY = cos(y);
...
} Or:
private void Foo(double x, double y)
{
static double cos(double value) => Math.Cos(value);
double cosX = cos(x);
double cosY = cos(y);
...
} Local functions - C# Programming Guide | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
New sign at town limits:
MyTown, TX
Estab. 1883
Elev 4500
Pop 5686
Zip 79830
--------------
Total 91899
If you can keep your head while those about you are losing theirs, perhaps you don't understand the situation.
|
|
|
|
|
Now this song is playing in my head: Old Town[^]
|
|
|
|
|
I got this one: Ghost Town[^]
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
That's a very special one, brings back memories!
|
|
|
|
|
(I'm ignoring backtracking regex here because it's dirty, and algorithmically less useful except for making it easier for the user to match text)
Anyway it's just a tiny functional programming language with only ()|?* 4 explicit operators and 1 implicit one.
Representing the regex programming language as code: Any regex is mathematically equivelent to the DFA state machine it represents, and can be converted algorithmically back and forth to and from a state machine and a regular expression. Perfect compilation/decompilation.
So you can use them to match text (boring!)
Or you can use them to generate code for state machines (less boring!)
And yet I've met a lot of programmers that either loathe them, are intimidated by them, or both.
They're wonderful little things, with interesting mathematical properties, but more importantly, they're useful for everything quick and dirty.
Real programmers use butterflies
|
|
|
|
|
Me think that most of us do not like it, because of bad experience of implementations in the past by different environments...
Almost all of my validations are done in regex, but never done too much of code generations to really use it there...
"The only place where Success comes before Work is in the dictionary." Vidal Sassoon, 1928 - 2012
|
|
|
|
|
If you do it right, regex facilitates rather than hinders code generation but Microsoft's engine is unfortunately limited in that regard. It does code generation, but it doesn't generate C# code for example. It could. It just doesn't.
Like I said in the OP, a regex is a state machine is a regex.
a state machine is code.
it's code all the way down.
ETA: If you stick to the basic operations and common syntactic sugar and avoid backtracking and other nonsense, most of the regex stuff is the same regardless of implementation.
Real programmers use butterflies
|
|
|
|
|
I very much enjoy Regex.
The complex elegance in a single line of code.
|
|
|
|
|
Have used some regexes in my article Translitera - Phonetic Typing in Some Indian Languages[^], which is a tool for transliterating from English to some Indian languages. The program uses regexes to identify patterns in each word, and hence split each word into manageable parts.
Of course, there are some situations which are not handled, there is always scope for improvement.
|
|
|
|
|
I use them for input validation. Things like dates and times are straightforward. Names are not! Even imposing cultural restrictions (two capitalised names and some fussing around the edges). Patrick O'Reilly-Smythe and Ian McDonald are about as complex as I allowed for members of our Rural Fire Brigade. I can't remember whether Giulio d'Angelo would pass or fail. If he joins up, I'll revisit the code.
My other major use is in (often throwaway) SED scripts, or of course grep. Things like extracting the word after Invalid user in security logs.
Another one I used recently was to reconstruct words that were hyphenated across lines in a OCR'd manual. Google translate barfs on the fragments of hyphenated words.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
|
Regex is black magic and sacrifices of caffeine and pizza offered in copious amounts is the only way to appease the beast.
I'm not sure how many cookies it makes to be happy, but so far it's not 27.
JaxCoder.com
|
|
|
|