It seems that you're using an outdated browser. Some things may not work as they should (or don't work at all).
We suggest you upgrade newer and better browser like: Chrome, Firefox, Internet Explorer or Opera

×
avatar
dtgreene: ...snip
Of course, you need to be careful not to put user input directly into the SELECT statement.
...snip
I wouldn't seriously allow the user any input anywhere :o)
avatar
nightcraw1er.488: Well, professionally 15 years as a SAS programmer, that's statistical programming not special forces :o)
I programmed in SAS (for DOS) from 1988 to 1997. Probably one of my first interactions with a computer.
Fun days. I remember writing meta-programs (programs that write other programs, which are then run) in SAS.
I even wrote a basic OMR (optical mark recognition) program in SAS (hey, it was the only language I knew back then).

avatar
dtgreene: Look up the International Obfuscated C Code Competition.
Shortly after learning C, I read this book:
http://www.amazon.com/Obfuscated-Other-Mysteries-Don-Libes/dp/0471578053

Recommended.
avatar
nightcraw1er.488: I wouldn't seriously allow the user any input anywhere :o)
User? What's that?
Post edited November 18, 2015 by mrkgnao
avatar
toxicTom: The problem with that is, that it always seems so clear and obvious when you write it... ;-)
avatar
adaliabooks: Yep, that's exactly my problem..
"No need to comment this, it's obvious what it does!"
Come back a few months later and wonder what the hell I was doing... XD
Months? I'm happy if I can remember what I meant when I wrote the code the night before.
avatar
nightcraw1er.488: Well, professionally 15 years as a SAS programmer, that's statistical programming not special forces :o)
avatar
mrkgnao: I programmed in SAS (for DOS) from 1988 to 1997. Probably one of my first interactions with a computer.
Fun days. I remember writing meta-programs (programs that write other programs, which are then run) in SAS.
I even wrote a basic OMR (optical mark recognition) program in SAS (hey, it was the only language I knew back then).

avatar
dtgreene: Look up the International Obfuscated C Code Competition.
avatar
mrkgnao: Shortly after learning C, I read this book:
http://www.amazon.com/Obfuscated-Other-Mysteries-Don-Libes/dp/0471578053

Recommended.
avatar
nightcraw1er.488: I wouldn't seriously allow the user any input anywhere :o)
avatar
mrkgnao: User? What's that?
Yes, I have tried to push the metadata driven code creation approach as well. Its a fun area.

Users: An unfortunate necessity in coding. This could range from the sweaty paw swiping masses to the poorly bolted together automated system which rejects your code 3 out of 4 times.
avatar
mrkgnao: And, of course, you don't need the following to write useful programs in perl:
print($_)
$| = 1;
foreach my $f (@{$$lang_arr_ref[1]{$os}})
$time =~ tr/ :/__/;
$field =~ s/(\(.*?\))/ $1/g;
$new_size =~ s/(\d)(?=(\d{3})+(\D|$))/$1\,/g;
[all are real life examples from MaGog's code]
As much as I love regexp for dealing with anything text related, in terms of readability they are the worst thing for me.
You can structure/format any programming language (well, most) in a way that you can easily follow the control flow/program logic. But a regular expression just sits there as an undistinctive blob and I have to slowly go through it to discover what it does.
And if I come upon a function where several of these blobs jump at me, late at night, after several hours of staring at the screen, my brain starts to hurt.
Which is why I (try to) give every longish regexp a comment about what it does.
low rated
Here is a silly little C example (note that I have not omitted any include statements):

int x[] = { 1,2,7,9,19, };

int main(void)
{
printf("%d", 3[x]);
}

Here are some oddities about this example:

1. Notice that the initializer for x has a comma at the end. That is, in fact, legal.

2. If you notice, I never declared printf anywhere, yet this still compiles. C does not require functions to be declared, though you can get into trouble depending on the types of the parameters and the return type. Note that gcc emits a warning here by default, and a C++ compiler will reject it entirely.

3. Here is the one that will probably surprise most people. Normally, you index the array with syntax x[3], which is rewritten by the compiler as *(x + 3). However, it turns out that you can write 3[x], which will be rewritten as *(3 + x). which means the same thing. So, believe it or not, 3[x] is legal C syntax.

4. Wait, where did the return statement go?
avatar
gooberking: If it were up to me I would just do HTML and CSS. Writing CSS and building responsive layouts is literally the only thing I care about or think I have any business doing. I don't see a lot of postings for that sort of thing.
That's what I do for a living (plus a lot of SEO). I do understand a thing or two when it comes to PHP and Javascript, but that's just enough to see what a piece of code does (if it isn't too complex). But my main focus lays on HTML, CSS and responsive designs (= one stylesheet for everything between a 1080p screen and a tiny iPhone 1). It took a bit to get used to designs exclusively written with % and em, but it's great to see how different a website can look on different devices (without creating separate mobile versions or stupid apps).

If you're interested in responsive layouts, here's an awesome website about the power of CSS: http://www.csszengarden.com/
Every design on this site has the same HTML code! And all designs work on all kinds of devices. A great source of inspiration ;)
avatar
dtgreene: Here is a silly little C example (note that I have not omitted any include statements):

int x[] = { 1,2,7,9,19, };

int main(void)
{
printf("%d", 3[x]);
}
[...]
4. Wait, where did the return statement go?
hate to be nitpicking, but iirc that brings you into the murky area of "undefined behaviour". That means: yes the you can compile that, but don't you try and use the return value of that function. There is no guarantee what the compiler will put there. So while that may be legal syntax according to the standard, just add your own personal law and declare it illegal :p.
avatar
Tallima: There are 10 kinds of people. Those who don't know anything about theoretical computational models, those who do, and those who know that trinary is the most efficient.

(I'm still waiting to see someone figure out how to build an e-nary computer -- that's technically the most efficient)
avatar
dtgreene: Do you, by any chance, have a link to any website that explains why trinary (or better yet, e-nary) is the most efficient?

(Note that I actually do have a mathematics background, so it is not a problem if that site is heavy on math.)
It has to do with radix economy.

I hope you understand it better than I. :)
low rated
avatar
dtgreene: Here is a silly little C example (note that I have not omitted any include statements):

int x[] = { 1,2,7,9,19, };

int main(void)
{
printf("%d", 3[x]);
}
[...]
4. Wait, where did the return statement go?
avatar
immi101: hate to be nitpicking, but iirc that brings you into the murky area of "undefined behaviour". That means: yes the you can compile that, but don't you try and use the return value of that function. There is no guarantee what the compiler will put there. So while that may be legal syntax according to the standard, just add your own personal law and declare it illegal :p.
Actually, it appears that you are actually incorrect in this case.
According to
http://stackoverflow.com/questions/18402853/must-the-int-main-function-return-a-value-in-all-compilers
the standard defines the return value of main() to be 0 if no return statement is reached. One of the answers cites § 3.6.1 from the standard.

(Note that this only applies to main(). Also, it apparently doesn't apply in C89, but does in later versions of the standard.)

In other words, the return value of main() in this example is in fact defined; my example does not, in fact, contain any undefined behavior. Surprised?
avatar
dtgreene: Do you, by any chance, have a link to any website that explains why trinary (or better yet, e-nary) is the most efficient?

(Note that I actually do have a mathematics background, so it is not a problem if that site is heavy on math.)
avatar
Tallima: It has to do with radix economy.

I hope you understand it better than I. :)
Ternary logic is actually very useful in black-box verification, because all signals/variables can have one of three values: False (0), True (1), Unknown (2). Years ago, I designed a verification system that used such ternary logic (over a binary computer, of course).

Also, did you know that the Russian developed a ternary computer in the 50's: https://en.wikipedia.org/wiki/Setun ?
avatar
immi101: hate to be nitpicking, but iirc that brings you into the murky area of "undefined behaviour". That means: yes the you can compile that, but don't you try and use the return value of that function. There is no guarantee what the compiler will put there. So while that may be legal syntax according to the standard, just add your own personal law and declare it illegal :p.
avatar
dtgreene: Actually, it appears that you are actually incorrect in this case.
According to
http://stackoverflow.com/questions/18402853/must-the-int-main-function-return-a-value-in-all-compilers
the standard defines the return value of main() to be 0 if no return statement is reached. One of the answers cites § 3.6.1 from the standard.

(Note that this only applies to main(). Also, it apparently doesn't apply in C89, but does in later versions of the standard.)

In other words, the return value of main() in this example is in fact defined; my example does not, in fact, contain any undefined behavior. Surprised?
well, my compiler uses C89 by default (gnu90 to be exact, but close enough), so ... :p
with your code: (i skipped the compile warnings)

~ $ gcc -o test test.c
~ $ ./test > /dev/null ; echo $?
1
~ $ gcc -std=c99 -o test test.c
~ $ ./test > /dev/null ; echo $?
0

but yes, that exception about main() was actually new to me. curios that they would write stuff like that into the standard.
though personally i rather remember one rule than one rule + one exception :D. And relying on that sort of implicit behaviour always calls for trouble imo. I rather keep my return 0; statement :)
avatar
gooberking: If it were up to me I would just do HTML and CSS. Writing CSS and building responsive layouts is literally the only thing I care about or think I have any business doing. I don't see a lot of postings for that sort of thing.
avatar
real.geizterfahr: That's what I do for a living (plus a lot of SEO). I do understand a thing or two when it comes to PHP and Javascript, but that's just enough to see what a piece of code does (if it isn't too complex). But my main focus lays on HTML, CSS and responsive designs (= one stylesheet for everything between a 1080p screen and a tiny iPhone 1). It took a bit to get used to designs exclusively written with % and em, but it's great to see how different a website can look on different devices (without creating separate mobile versions or stupid apps).

If you're interested in responsive layouts, here's an awesome website about the power of CSS: http://www.csszengarden.com/
Every design on this site has the same HTML code! And all designs work on all kinds of devices. A great source of inspiration ;)
Good to know such jobs exist. I've tended to get tossed all the layout stuff in the past since I like it and others don't seem to. I was never educated in doing fixed layouts so pixel avoidance was always my default. Using em's as a measurement was something I kinda figured out on my own, but have gotten pretty sold on.

I knew about csszengarden but I haven't looked at it in quite some time. I think there is a lot of stuff I haven't seen.
Post edited November 19, 2015 by gooberking
avatar
immi101: but yes, that exception about main() was actually new to me. curios that they would write stuff like that into the standard.
though personally i rather remember one rule than one rule + one exception :D. And relying on that sort of implicit behavior always calls for trouble imo. I rather keep my return 0; statement :)
The actual return value from a program can only be from 0 to 255. 0 returned means effectively the program ended with no issues.

This is heavily useful for bash and shell programming, where you attach actions based on if it succeeded or failed.

My experience with shell programming is fairly limited; But gluing programs together to make something more powerful than a single program is insanely fun (if a little annoying to debug or figure out)
Question for CMD wizards. Say I have a directory tree as follows:
D:\
D:\data\
D:\data\a\
D.\data\a\some stuff
D:\data\b\
D:\data\b\other stuff
I want to copy D:\data\a\ to E:\backup\data\a\ - except I want to keep all attributes, ACLs, etc. of the data directory and below, not just from a and below. "b" and anything else in the data folder should NOT be included.

If I do robocopy D:\data\a E:\backup\data\a /E /COPYALL /B, a and below is correct, but how do I keep all attributes and security info from D:\data?