Coding: Fleeting Thoughts

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

User avatar
Thesh
Made to Fuck Dinosaurs
Posts: 6580
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Colorado

Re: Coding: Fleeting Thoughts

Postby Thesh » Fri Oct 03, 2014 5:00 pm UTC

Xeio wrote:So, then we have a method that needs to go back and update those records. But rather than say, pass a list, no no, we pass a string of comma-seperated keys to update. (Why? Who knows!)

That's common, especially before SQL 2008 added Table Valued Parameters. People get it in their head that they have to use stored procedures, so instead of a parameterized query, they use a stored procedure even though it doesn't work very well for their purpose, just because someone said stored procedures were faster (even though I've seen code where parsing the list took longer than executing the query itself!). So yeah, if you have a list, either use TVP or a parameterized query. Usually, however, you have a stored procedure that parses the list and returns a table.
Summum ius, summa iniuria.

User avatar
Xeio
Friends, Faidites, Countrymen
Posts: 5101
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\
Contact:

Re: Coding: Fleeting Thoughts

Postby Xeio » Fri Oct 03, 2014 6:45 pm UTC

Might be nicer if it actually parsed the passed list, at least that could easily use the index on the table for the updates. In its current state it iterates every key on the table to compare to the CSV string...

Code: Select all

UPDATE FOOTABLE
SET PROCESS_FLAG='Y'
WHERE CHARINDEX(CAST(FOOKEY AS VARCHAR(20))+',',@keylist)>0
I suppose it's possible MS SQL Server can optimize that, but I'd be skeptical. Calling the stored procedure once per key would probably be significantly faster, it's not very many in each batch update.

Granted, the table doesn't have billions of records, and this runs at most once per night so performance really won't matter. It's more the concept of the thing is so horrible.

speising
Posts: 2354
Joined: Mon Sep 03, 2012 4:54 pm UTC
Location: wien

Re: Coding: Fleeting Thoughts

Postby speising » Fri Oct 03, 2014 6:51 pm UTC

We once had a batch job running nightly on our server, which would take about 8 hours to complete. When challenged about the jobs efficiency, the developer responsible explained that it didn't matter, since it finished before the daily business started anyway.

Another colleague then optimized the job to run in half an hour, regardless.

User avatar
Thesh
Made to Fuck Dinosaurs
Posts: 6580
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Colorado

Re: Coding: Fleeting Thoughts

Postby Thesh » Fri Oct 03, 2014 7:14 pm UTC

Wow, that is horrible, the table and column names are allcaps!

EDIT:

You know, for writing things like CSV writers/parsers, it would be nice if you could have code that only ran on the first, last, or subsequent calls. Something like this:

Code: Select all

for (i=0; i<a.length; i++)
first:
    list = ""; //contrived
subsequent:
    list += ",";
all:
    list += a[i];
last:
    //This doesn't really fit my example
end for


Of course, the last becomes kind of dangerous, since it can only run after i = a.length.
Summum ius, summa iniuria.

User avatar
Xeio
Friends, Faidites, Countrymen
Posts: 5101
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\
Contact:

Re: Coding: Fleeting Thoughts

Postby Xeio » Fri Oct 03, 2014 7:53 pm UTC

Thesh wrote:Wow, that is horrible, the table and column names are allcaps!
That's our coding standard. SQL is all caps, all the time.

Not really sure why.
speising wrote:We once had a batch job running nightly on our server, which would take about 8 hours to complete. When challenged about the jobs efficiency, the developer responsible explained that it didn't matter, since it finished before the daily business started anyway.

Another colleague then optimized the job to run in half an hour, regardless.
If I could have solved it without needing to refactor multiple stored procedures, a WCF service call, and the caller method I wasn't even working in...

There's also the issue that this is for a shorter timescale release where I don't want to make sweeping changes like that. So I'm not going to introduce that risk over a couple seconds (at most) on the prod server nightly.

It will just slowly eat away at my mind, like a bunch of other things I wish I didn't know about in the codebase.

User avatar
phlip
Restorer of Worlds
Posts: 7572
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: Coding: Fleeting Thoughts

Postby phlip » Sat Oct 04, 2014 4:45 am UTC

So... What does the code do if one key is a suffix of another key? If you have, say, keys "100" and "2100"?

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

User avatar
felltir
has a sniper scope and a trigger finger.
Posts: 2493
Joined: Tue Mar 04, 2008 5:01 pm UTC
Location: Back in't home town. Never at home.
Contact:

Re: Coding: Fleeting Thoughts

Postby felltir » Sat Oct 04, 2014 7:45 am UTC

I'm writing a talk about the weirdnesses of ruby (as a ruby programmer) and some of them are amazing.
Spoiler:
RoadieRich wrote:He's a super flexible furry martial artist from London. She is a Rabbit breeding mad scientist from Michigan. They fight crime!
The Great Hippo wrote:I THINK THE SOLAR SYSTEM MIGHT BE AN ATOM OF OXYGEN.


Blog

he/him/his

User avatar
Xeio
Friends, Faidites, Countrymen
Posts: 5101
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\
Contact:

Re: Coding: Fleeting Thoughts

Postby Xeio » Sat Oct 04, 2014 4:03 pm UTC

phlip wrote:So... What does the code do if one key is a suffix of another key? If you have, say, keys "100" and "2100"?
In practice that won't happen, all keys start with one of two letters followed by 7-8 digits.

But you bring up another point as to why this is terrible.

User avatar
Xenomortis
Not actually a special flower.
Posts: 1448
Joined: Thu Oct 11, 2012 8:47 am UTC

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Tue Oct 07, 2014 10:36 am UTC

Ticket:
"Thing A is printing a warning and it didn't used to"

Fix:
Comment out warning.

Spoiler:
(Warning is about Thing B, which confused me because Thing A doesn't look like it has anything to do with Thing B).

For some reason, Thing A and Thing B (Python) both derive from the same class (Class C) - it makes sense for Thing B (which is a "dummy" instance of C), but not for Thing A.
I'm sure the original author of this code had his reasons, but I'm also sure they were wrong and I choose to believe he was incompetent.

Thing B never actually did anything, so commenting out a now useless warning is fine.
(Actually that's not true; it has a 1 second sleep in it that would be called a fair bit in the case of the warning never being reached)

A lot of "not C's" actually derive from C in this particular area of the code base.
The entire mechanism is now redundant but these things linger...
Image

User avatar
Sizik
Posts: 1256
Joined: Wed Aug 27, 2008 3:48 am UTC

Re: Coding: Fleeting Thoughts

Postby Sizik » Tue Oct 07, 2014 2:50 pm UTC

Just for kicks, I wanted to try to generate doubles from a uniform distribution over the entire range of double values.

(Java)

Code: Select all

public static void main(String[] args) {

   Random rand = new Random();
   byte[] exp_b = new byte[256]; // for exponent generation
   while(true)
   {
      // Random significand
      long sig = rand.nextLong();
      sig &= 0xFFFFFFFFFFFFFL;

      // Generate random exponent such that
      // exponent e is twice as likely as e-1.
      rand.nextBytes(exp_b);
      long exp = 2047;
      for(int i = 2047; i >= 0; i--)
      {
         int index = i / 8;
         int rel = 1 << (i % 8);
         int bit = exp_b[index] & rel;
         
         if(bit == 1)
         {
            break;
         }
         else
         {
            exp--;
         }
      }

      // Random sign bit
      long sign = rand.nextBoolean() ? Long.MIN_VALUE : 0;

      // Put it together
      long l = sign | (exp << 52) | sig;

      // print for debugging
      System.out.println("Sign: " + Long.toBinaryString(sign));
      System.out.println("Exp: " + Long.toBinaryString(exp << 52));
      System.out.println("Sig: " + Long.toBinaryString(sig));
      System.out.println("Double: " + Long.toBinaryString(l));

      // Convert to double
      double d = Double.longBitsToDouble(l);
      System.out.println("d:" + d);

      // faster method, but less precision (and no sign)
      double d2 = rand.nextDouble() * Double.MAX_VALUE;
      System.out.println("d2:" + d2);

      // wait and loop until stopped
      try {
         Thread.sleep(1000);
      } catch (InterruptedException e) {
         break;
      }
   }
}   


Predictably, most of the values fall in the 10^300 range.
she/they
gmalivuk wrote:
King Author wrote:If space (rather, distance) is an illusion, it'd be possible for one meta-me to experience both body's sensory inputs.
Yes. And if wishes were horses, wishing wells would fill up very quickly with drowned horses.

User avatar
Xenomortis
Not actually a special flower.
Posts: 1448
Joined: Thu Oct 11, 2012 8:47 am UTC

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Tue Oct 07, 2014 2:58 pm UTC

Sizik wrote:Just for kicks, I wanted to try to generate doubles from a uniform distribution over the entire range of double values.

Isn't this the same problem as generating 64 bit ints that fit a uniform distribution?
Image

User avatar
Sizik
Posts: 1256
Joined: Wed Aug 27, 2008 3:48 am UTC

Re: Coding: Fleeting Thoughts

Postby Sizik » Tue Oct 07, 2014 3:02 pm UTC

Xenomortis wrote:
Sizik wrote:Just for kicks, I wanted to try to generate doubles from a uniform distribution over the entire range of double values.

Isn't this the same problem as generating 64 bit ints that fit a uniform distribution?


No, because picking a value between 1 and 2 would be just as likely as picking a value between 2 and 4, since the exponent would be evenly distributed.

Edit: it's uniformly picking a random number between (approximately) -10^308 and 10^308, not uniformly picking a random double from the set of all doubles.
she/they
gmalivuk wrote:
King Author wrote:If space (rather, distance) is an illusion, it'd be possible for one meta-me to experience both body's sensory inputs.
Yes. And if wishes were horses, wishing wells would fill up very quickly with drowned horses.

User avatar
Xenomortis
Not actually a special flower.
Posts: 1448
Joined: Thu Oct 11, 2012 8:47 am UTC

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Tue Oct 07, 2014 3:11 pm UTC

Sizik wrote:Edit: it's uniformly picking a random number between (approximately) -10^308 and 10^308, not uniformly picking a random double from the set of all doubles.

I thought my (mis)interpretation of your statement didn't gel with the code. :D

Edit:
Double.longBitsToDouble(...);
I can't decide if I like that more or less than pointer casting shenanigans.
Image

Wonderbolt
Posts: 212
Joined: Thu Mar 13, 2014 12:11 pm UTC

Re: Coding: Fleeting Thoughts

Postby Wonderbolt » Fri Oct 10, 2014 8:59 pm UTC

Well, I'm trying to get over my hate and fear of all C++ code I've ever seen and actually learn the language. Yay for me.

I'm currently stuck with Windows, so I have one question: is there any reason to choose MingW g++ over Visual C++ or the other way around for learning the language? Also, could someone explain to me the difference between those bazillion different versions of Visual Studio?

*hasn't used Windows for anything for a looooooong time*

User avatar
Thesh
Made to Fuck Dinosaurs
Posts: 6580
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Colorado

Re: Coding: Fleeting Thoughts

Postby Thesh » Fri Oct 10, 2014 9:33 pm UTC

Depends on what you are used to. A newer version of GCC will have better C++11 support, Visual Studio has a much more friendly environment (especially the debugger) and can be a lot easier to work with in many cases. As for the versions, web and team foundation are fairly self explanatory, but Windows and Windows desktop are confusing, but basically Windows desktop is mainly for classic windows apps, and windows is for windows store apps. You probably want the one for Windows Desktop.
Summum ius, summa iniuria.

User avatar
Xenomortis
Not actually a special flower.
Posts: 1448
Joined: Thu Oct 11, 2012 8:47 am UTC

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Sat Oct 11, 2014 10:12 am UTC

Wonderbolt wrote:I'm currently stuck with Windows, so I have one question: is there any reason to choose MingW g++ over Visual C++ or the other way around for learning the language? Also, could someone explain to me the difference between those bazillion different versions of Visual Studio?

So long as you're using the latest Visual Studio (2014), not really. C++11 support is pretty good whilst MinGW isn't always reliable (and if you want 64-bit, it gets worse - you need a separate install for the 64-bit version (which is worse in terms of support).

MinGW is more convenient if you're looking at cross-platform code since you're not worried about any of the extraneous VS stuff (.sln files etc).
But VS is much easier.
And debugging is much easier with VS.
Image

korona
Posts: 495
Joined: Sun Jul 04, 2010 8:40 pm UTC

Re: Coding: Fleeting Thoughts

Postby korona » Sat Oct 11, 2014 10:44 am UTC

I haven't used it much (I usually develop in Linux using vim/gcc/gdb) but Visual Studio seems to be a decent IDE.

User avatar
Yakk
Poster with most posts but no title.
Posts: 11128
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Sun Oct 12, 2014 12:20 pm UTC

I can break the latest VS C++11 implementation without trying. And U3 and U2 generate invalid optimized code (enough to cause crashes) in corner cases.

U1 seems more stable, and they claim the U2U3 problems are fixed in U4.

Be careful with expression SFINAE and {} initialization in particular. If you get sn internal compiler error, try adding newlines (!).

But you probably do not have to worry about these as a new C++ programmer. Even the invalid code was a few times in a many million line codebase.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

User avatar
Jplus
Posts: 1721
Joined: Wed Apr 21, 2010 12:29 pm UTC
Location: Netherlands

Re: Coding: Fleeting Thoughts

Postby Jplus » Sun Oct 12, 2014 12:53 pm UTC

felltir wrote:I'm writing a talk about the weirdnesses of ruby (as a ruby programmer) and some of them are amazing.

Great! When can we read/see your talk?

Wonderbolt wrote:Well, I'm trying to get over my hate and fear of all C++ code I've ever seen and actually learn the language. Yay for me.

Welcome to the wonderful world of C++. May the spirits of Alex Stepanov and Dave Abrahams be with you. (Both of them are still alive, mind you.)
"There are only two hard problems in computer science: cache coherence, naming things, and off-by-one errors." (Phil Karlton and Leon Bambrick)

coding and xkcd combined

(Julian/Julian's)

User avatar
Dinosaur!
Posts: 30
Joined: Fri Dec 14, 2012 8:45 pm UTC
Location: Santa Cruz, CA

Re: Coding: Fleeting Thoughts

Postby Dinosaur! » Mon Oct 13, 2014 1:26 am UTC

Man, I'm really hating the process of learning C. I've been programming for a few years now, and have learned a bit each C++, Java, and Perl in that order. Writing typedef and struct and calloc/malloc/free and char* and '\0' and blah* and &blah all hurt my soul. I'm sure I'll get over it, but it just seems like everything in this language is a far more frustrating, crotchety version of what I really want to do.

jareds
Posts: 436
Joined: Wed Jan 03, 2007 3:56 pm UTC

Re: Coding: Fleeting Thoughts

Postby jareds » Mon Oct 13, 2014 2:56 am UTC

Yakk wrote:If you get sn internal compiler error, try adding newlines (!).

Sorry for the relatively contentless post, but... :shock: :shock: :shock:

Edit: In fairness, one can hope this represents the reading of uninitialized memory within the compiler rather than terribly intertwined lexing and parsing, per se.

User avatar
PM 2Ring
Posts: 3713
Joined: Mon Jan 26, 2009 3:19 pm UTC
Location: Sydney, Australia

Re: Coding: Fleeting Thoughts

Postby PM 2Ring » Mon Oct 13, 2014 4:09 am UTC

Dinosaur! wrote:Man, I'm really hating the process of learning C. I've been programming for a few years now, and have learned a bit each C++, Java, and Perl in that order. Writing typedef and struct and calloc/malloc/free and char* and '\0' and blah* and &blah all hurt my soul. I'm sure I'll get over it, but it just seems like everything in this language is a far more frustrating, crotchety version of what I really want to do.


Look on the bright side: if you ever decide to learn an assembler language, your soul will be grateful for its experience with C. There's an old C programer saying: "C is so close to the metal that you can smell the registers".

FWIW, I learned C in the early 1980s and I'm still fond of it, but I must admit that I mostly write in Python these days, although I occasionally do stuff in awk and the bash shell scripting language.

User avatar
Xenomortis
Not actually a special flower.
Posts: 1448
Joined: Thu Oct 11, 2012 8:47 am UTC

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Mon Oct 13, 2014 1:18 pm UTC

I have a lot of python classes that talk to hardware.
There are a lot of instances of each.
I need a test environment where these objects do not talk to hardware.

Is this evil?

Code: Select all

##Original##

class A:
  #stuff

x = A(...)
y = A(...)

Code: Select all

##Changed##

class _A:
  #stuff

class _AFake:
  #stuff

A = _A if live else _AFake
x = A(...)
y = A(...)
Image

User avatar
karhell
Posts: 687
Joined: Wed Jun 19, 2013 4:56 pm UTC
Location: Breizh

Re: Coding: Fleeting Thoughts

Postby karhell » Mon Oct 13, 2014 1:52 pm UTC

While it will certainly work, you'll end up with a lot of duplicate code.

Would it be possible to simulate the hardware and have the connexions configurable ? That way, you can simply swap config files between test and production with minimal changes to your code base.
AluisioASG wrote:191 years ago, the great D. Pedro I drew his sword and said: "Indent thy code or die!"
lmjb1964 wrote:We're weird but it's okay.
ColletArrow, katakissa, iskinner, thunk, GnomeAnne, Quantized, and any other Blitzers, have fun on your journey!

User avatar
Xenomortis
Not actually a special flower.
Posts: 1448
Joined: Thu Oct 11, 2012 8:47 am UTC

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Mon Oct 13, 2014 2:51 pm UTC

karhell wrote:While it will certainly work, you'll end up with a lot of duplicate code.

Right, but I don't really see an easy way to avoid that.

Normally this stuff is configured by software developers using Spring where the substitution isn't too bad (although I would prefer it to be done at a lower level - mainly to avoid this situation) - hardware motors simply get two definitions (and offline is pretty simple).
But sometimes "non-developers" write python code to do things themselves, and these scripts are the very last thing to run, and sometimes they talk to hardware themselves to do things.

Usually it doesn't matter - we can usually skip these devices on an offline startup and it doesn't matter - but for the piece of work I want to do, I would very much like them to exist.
Image

User avatar
Thesh
Made to Fuck Dinosaurs
Posts: 6580
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Colorado

Re: Coding: Fleeting Thoughts

Postby Thesh » Mon Oct 13, 2014 2:57 pm UTC

When writing unit tests, that would usually be done with dependency injection. If you want your program to run in full with mock objects, then can't you have two files, one for your real class and one for your mock objects?
Summum ius, summa iniuria.

User avatar
Jplus
Posts: 1721
Joined: Wed Apr 21, 2010 12:29 pm UTC
Location: Netherlands

Re: Coding: Fleeting Thoughts

Postby Jplus » Mon Oct 13, 2014 6:13 pm UTC

Dinosaur! wrote:Man, I'm really hating the process of learning C. I've been programming for a few years now, and have learned a bit each C++, Java, and Perl in that order. Writing typedef and struct and calloc/malloc/free and char* and '\0' and blah* and &blah all hurt my soul. I'm sure I'll get over it, but it just seems like everything in this language is a far more frustrating, crotchety version of what I really want to do.

I think PM 2Ring gave you a good, insightful reply, but I would like to offer you another perspective. Spoilered for unsollicited comment/advice.

Spoiler:
Of course I don't know why you're learning C in the first place nor how much choice you have in this, but it might be worth considering for you to switch to another language. Each language has its own strengths and weaknesses, and besides not every language being equally fit for every purpose, not every language fits equally well to your personality, either. From what I read I get the impression that you just want to write a good program, using all of your attention and energy to focus on things like algorithms, datastructures, reusability of your code, interaction with users, etcetera. Dealing with technical details doesn't fit in that picture, so you might be better off with a language that moves such details as much out of your way as possible.

Now, I believe it will be hard to find a language that offers just that but still lets you have the raw performance of C and C++. However, you can have Java-esque performance in a language that doesn't confront you with much technical details at all. Scala, Julia and LuaJIT come to mind, although those differ considerably in other respects. If performance is not that important you have much more options still, for example Python and Ruby.

The primary message of this reply is not just that there are alternatives, though; it's that it's absolutely OK if C is not your thing and choosing a different language can be a perfectly good choice that makes you just as good a programmer (ceteris paribus) as someone who does like C.
"There are only two hard problems in computer science: cache coherence, naming things, and off-by-one errors." (Phil Karlton and Leon Bambrick)

coding and xkcd combined

(Julian/Julian's)

korona
Posts: 495
Joined: Sun Jul 04, 2010 8:40 pm UTC

Re: Coding: Fleeting Thoughts

Postby korona » Mon Oct 13, 2014 8:28 pm UTC

Xenomortis wrote:
karhell wrote:Normally this stuff is configured by software developers using Spring where the substitution isn't too bad [...]

The Spring framework - a large library that neatly solves problems nobody ever had before using the framework.

Well, that is my impression of such frameworks but I'm a low level developer, so YMMV.

User avatar
Xenomortis
Not actually a special flower.
Posts: 1448
Joined: Thu Oct 11, 2012 8:47 am UTC

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Mon Oct 13, 2014 8:30 pm UTC

My major complaint with it is that typing XML is really not good for my RSI.
Image

User avatar
Dinosaur!
Posts: 30
Joined: Fri Dec 14, 2012 8:45 pm UTC
Location: Santa Cruz, CA

Re: Coding: Fleeting Thoughts

Postby Dinosaur! » Tue Oct 14, 2014 1:46 am UTC

Jplus wrote:
Dinosaur! wrote:Man, I'm really hating the process of learning C. I've been programming for a few years now, and have learned a bit each C++, Java, and Perl in that order. Writing typedef and struct and calloc/malloc/free and char* and '\0' and blah* and &blah all hurt my soul. I'm sure I'll get over it, but it just seems like everything in this language is a far more frustrating, crotchety version of what I really want to do.

I think PM 2Ring gave you a good, insightful reply, but I would like to offer you another perspective. Spoilered for unsollicited comment/advice.

Spoiler:
Of course I don't know why you're learning C in the first place nor how much choice you have in this, but it might be worth considering for you to switch to another language. Each language has its own strengths and weaknesses, and besides not every language being equally fit for every purpose, not every language fits equally well to your personality, either. From what I read I get the impression that you just want to write a good program, using all of your attention and energy to focus on things like algorithms, datastructures, reusability of your code, interaction with users, etcetera. Dealing with technical details doesn't fit in that picture, so you might be better off with a language that moves such details as much out of your way as possible.

Now, I believe it will be hard to find a language that offers just that but still lets you have the raw performance of C and C++. However, you can have Java-esque performance in a language that doesn't confront you with much technical details at all. Scala, Julia and LuaJIT come to mind, although those differ considerably in other respects. If performance is not that important you have much more options still, for example Python and Ruby.

The primary message of this reply is not just that there are alternatives, though; it's that it's absolutely OK if C is not your thing and choosing a different language can be a perfectly good choice that makes you just as good a programmer (ceteris paribus) as someone who does like C.


Thanks for the response. I'm learning C as a mandatory part of a mandatory class (Abstract Data Structures @ UCSC, following CLRS 3rd ed), so I don't have a choice. And yes, you do seemed to have picked up on what attracts me to programming, and what does not. That's what I love about Java and Perl; I can simply write down the important parts, knowing that the compiler/interpreter/runtime environment will take care of the details.

The fact that I take a (perhaps large) performance hit is much less of a concern to me than the fact that the code itself takes longer to write and involves a lot more head-scratching. Of course, this is from the perspective of someone who is programming in a learning environment, not in a line of work where program performance matters much, so I guess that stance could easily change in the future.

And I sure ain't trying to say that C is a bad language used by bad people or whatever (dog knows Perl is largely C, and Java in C++). It just rubs me the wrong way. I guess being close enough to the metal to smell the registers feels like being close enough to the fire to smell my hair burning, while being asked to rub my belly and tap my head (and by the way a hand is not a hand, it's an array of five digits).

edit: And oh yeah, re: the last paragraph from J+. Whatever people might think of a given programming language, saying that someone is a worse programmer for using it is like saying someone is a worse human because of the language they speak. So I ain't worried about that :)

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Tue Oct 14, 2014 9:42 am UTC

I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

Wonderbolt
Posts: 212
Joined: Thu Mar 13, 2014 12:11 pm UTC

Re: Coding: Fleeting Thoughts

Postby Wonderbolt » Tue Oct 14, 2014 9:45 am UTC

PM 2Ring wrote:Look on the bright side: if you ever decide to learn an assembler language, your soul will be grateful for its experience with C. There's an old C programer saying: "C is so close to the metal that you can smell the registers".

Interestingly enough, I found that I only really felt that I 'got' C after I learned some assembly.

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Tue Oct 14, 2014 9:50 am UTC

Wonderbolt wrote:
PM 2Ring wrote:Look on the bright side: if you ever decide to learn an assembler language, your soul will be grateful for its experience with C. There's an old C programer saying: "C is so close to the metal that you can smell the registers".

Interestingly enough, I found that I only really felt that I 'got' C after I learned some assembly.


Yeah. I wrote a C compiler once. Not even remotely standard C, but something much more buggy and ill-defined. Still, I learned so much about C those weeks. These were mostly things I was aware of before, but didn't have any sort of feeling for. Very good exercise.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
PM 2Ring
Posts: 3713
Joined: Mon Jan 26, 2009 3:19 pm UTC
Location: Sydney, Australia

Re: Coding: Fleeting Thoughts

Postby PM 2Ring » Tue Oct 14, 2014 11:32 am UTC

Wonderbolt wrote:
PM 2Ring wrote:Look on the bright side: if you ever decide to learn an assembler language, your soul will be grateful for its experience with C. There's an old C programer saying: "C is so close to the metal that you can smell the registers".

Interestingly enough, I found that I only really felt that I 'got' C after I learned some assembly.


I can understand that. FWIW, I hadn't even heard of C when I learned my first assembler language (IBM 360). But then, C was pretty obscure in 1974. :) I started learning C in late 1980, on a fairly limited implementation. I didn't really get into it properly until a few years later, on the Amiga 2000.

I guess almost all the early C programmers had at least some familiarity with an assembler language before they started using C, so learning about how C handles memory, especially pointers, was fairly straightforward. If you think of C as a pseudo high level language that forces you to deal with almost all the details of memory handling it can be tedious, but if you think of it as a souped-up assembler, it's not so bad. :)

User avatar
Yakk
Poster with most posts but no title.
Posts: 11128
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Wed Oct 15, 2014 1:59 am UTC

C and C++ are only pseudo-assemblers. Both leave unspecified and undefined behavior rampant, which gives room for the optimizer to change what you wrote into more efficient assembly.

This also means that you can easily be burned by such unspecified and undefined behavior.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

User avatar
PM 2Ring
Posts: 3713
Joined: Mon Jan 26, 2009 3:19 pm UTC
Location: Sydney, Australia

Re: Coding: Fleeting Thoughts

Postby PM 2Ring » Wed Oct 15, 2014 3:15 am UTC

Or you quickly learn not to invoke said undefined or unspecified behaviour. :)

Kids these days have it too easy. Back on the Amiga, a bad pointer operation could crash the machine, and then you'd have to wait a couple of minutes for the machine to boot up, giving you time to contemplate the stupid error you'd just made. You tend to program cautiously in that sort of environment. :)

User avatar
phlip
Restorer of Worlds
Posts: 7572
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: Coding: Fleeting Thoughts

Postby phlip » Wed Oct 15, 2014 5:32 am UTC

PM 2Ring wrote:Kids these days have it too easy. Back [...] then you'd have to wait a couple of minutes [...]

Excuse me while I go fetch my mother, who did a lot of programming back in the day for batch processors (for which you'd write your code, put it in the queue, and come back the next day to receive your result and/or error) to laugh at you.

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

User avatar
Thesh
Made to Fuck Dinosaurs
Posts: 6580
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Colorado

Re: Coding: Fleeting Thoughts

Postby Thesh » Wed Oct 15, 2014 5:38 am UTC

Couldn't you cause a BSoD in Windows 95/98/ME because it didn't fully protect memory?
Summum ius, summa iniuria.

korona
Posts: 495
Joined: Sun Jul 04, 2010 8:40 pm UTC

Re: Coding: Fleeting Thoughts

Postby korona » Wed Oct 15, 2014 8:39 am UTC

I recommend anyone who really wants to understand how computers work to write a toy kernel / operating system. The x86 architecture is very well documented so this is not as hard as it sounds. Doing so will certainly make you understand the design decisions that went into C.

Ubik
Posts: 1016
Joined: Thu Oct 18, 2007 3:43 pm UTC

Re: Coding: Fleeting Thoughts

Postby Ubik » Wed Oct 15, 2014 9:05 am UTC

C++ will be complete when any string of identifiers, keywords and special characters the language recognizes, compiles without errors.


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 9 guests