u/CirdanValen - 17 Archived Voat Posts in v/programming
u/CirdanValen
  • home
  • search

u/CirdanValen

0 posts · 17 comments · 17 total

Active in: v/programming (17)

  • ‹‹‹
  • ‹‹
  • ‹
  • 1
  • ›
  • ››
  • ›››
Comment on: After working in JavaScript for a while, I feel that the class concept is redundant and no longer required

Just as a side note ... I'm not the author of the blog post

1 20 Jun 2016 14:04 u/CirdanValen in v/programming
Comment on: After working in JavaScript for a while, I feel that the class concept is redundant and no longer required

I used to be heavy into OOP, design patterns, inheritance, etc. for years. I recently switched to purely procedural/functional programming in a adhoc way and it is SO MUCH BETTER. Structs and functions, nothing more is needed. Screw OOP. Screw UML. Screw inheritance. Screw public/private members. It all leads to really crappy, slow and inflexible code.

https://mollyrocket.com/casey/stream_0019.html

Edit: I'm not the author of the blog post, but he describes the problem and solution well

10 20 Jun 2016 04:17 u/CirdanValen in v/programming
Comment on: [Why does my code work] I have created a parser in C and if I do not allocate and immediately free an array it breaks.

Some things I noticed

1) You should be able to use calloc to allocate memory and zero it, so you don't have to loop and set it all to zero.

2) I'm not quite sure what you're trying to do here, but I don't think atoi(inputBufferSubset) does what you think it does. If you want the value at inputBufferSubset[0] then you need to do *inputBufferSubset. In which case, you could just do char position = *inputBufferSubset; If you need the value of multiple chars, you'll need to combine the bytes into an integer. (int)*inputBufferSubet would work, but it would include the junk after the value. In this case you would need the length and mask it or bitshift. Alternatively, put the value into a zeroed char[] coinCount; and do (int)*coinCount. EDIT: I may be wrong with with this point. I tested it real quickly and it always returned 0..but in retrospect it should have worked.

3) positionCountArray = allocIntBuffer(8); requestArray = allocIntBuffer(8); There's probably more code than what is here, but hopefully you are freeing these at some point.

I would write the code totally differently:

#define US 31
void getToken(char* input, unsigned int inputLength, char* result, unsigned int* resultLength) 
{   
    int i = 0;
    for(; i < inputLength; i++) {
        if(input[i] == US) {
               break;
        }
    }
    *resultLength = i;
    memcpy(result, input, i);
}
void main(...) {
    char input[8] = {48, 31, 49, 31, 49, 48, 31, 30};
    int inputLength = 8; // Not going to use strlen because no \0
    char token[8] = {}; // results can never be longer than the input
    int resultLength = 0;
    int index = 0;
   // Get motor
   getToken(&input[index], inputLength, token, &resultLength);
   int motor = token[0];
   index += resultLength + 1;
   // Get second unit (ASCII 49)
   getToken(&input[index], inputLength-index, token, &resultLength);
   int secondUnit = token[0];
  index += resultLength + 1;
  // Get quantity
  getToken(&input[index], inputLength-index, token, &resultLength);
  int coinCount = (int)*token & 0x0000FFFF; // Don't forget about endianness!
     and bitshift to get the integer value. I can't imagine someone would want > 99 coins, but who knows. */
 // etc...
}

It's really rough, incomplete, and probably broken but I think you get the idea. Your really should try to avoid calling malloc & free so many times. Eventually the memory will become fragmented and memory allocation will fail. Hopefully this helps.

0 16 Jun 2016 04:23 u/CirdanValen in v/programming
Comment on: Which programming language to learn first [infographic]

Everyone should just learn c and be done with it

14 14 Jun 2016 19:00 u/CirdanValen in v/programming
Comment on: (Brian Will) Object-Oriented Programming is Garbage: 3800 SLOC example

Java is a poor excuse for a programming langue and really needs to die the death it deserves. C# I could do without an ide

0 22 Mar 2016 20:31 u/CirdanValen in v/programming
Comment on: (Brian Will) Object-Oriented Programming is Garbage: 3800 SLOC example

I use a text editor and command line while writing my own OpenGL graphics engine in C. IDEs are extremely over rated.

1 22 Mar 2016 18:15 u/CirdanValen in v/programming
Comment on: (Brian Will) Object-Oriented Programming is Garbage: 3800 SLOC example
:/myMethodName
n
n
n

Found it! Man that was hard, I need a drink.

0 22 Mar 2016 18:13 u/CirdanValen in v/programming
Comment on: HOW TO: Move from github to BitBucket. I just moved 4 private repositories and it took me 10 minutes.

Or if you want to self-host:

  • https://gitlab.com/
  • https://gogs.io/
16 25 Feb 2016 06:48 u/CirdanValen in v/programming
Comment on: Alternatives to notepad++

I really like Atom.....but that's another SJW platform (GitHub)

1 17 Feb 2016 20:56 u/CirdanValen in v/programming
Comment on: Anyone know what happened to Dev-C++ and Orwell?

Ah, I forgot. Voat is a safespace for anti-M$ers

2 09 Feb 2016 02:19 u/CirdanValen in v/programming
Comment on: Anyone know what happened to Dev-C++ and Orwell?

It was because visual studio wasn't free until relatively recently. Since MSVC is free, not much reason to use anything else.

1 08 Feb 2016 21:47 u/CirdanValen in v/programming
Comment on: Passing a dynamic array into an OpenGL vertex buffer? Any thoughts.

&vertices[0] should work. All it needs is the size and the address of the beginning of the array. If you update vertices[] you will have to call glBufferData again, as it copies the array.

2 14 Sep 2015 04:47 u/CirdanValen in v/programming
Comment on: Linus Torvalds is tired indeed of "trivially obvious improvements" that are actually buggy

Visual reward as in someone notices their changes, or it has some cascading effect on the development or community. Nobody wants to fix the obscure bug that effects 5 people.

2 11 Sep 2015 21:11 u/CirdanValen in v/programming
Comment on: Is it worth spending the time to learn Emacs today?

IntelliJ AKA AndroidStudio

0 10 Jul 2015 21:11 u/CirdanValen in v/programming
Comment on: Is it worth spending the time to learn Emacs today?

Not to start a Holy War...but you could try learning VIM. In my opinion it has a less steep learning curve, but still provides a lot of utility and efficiency that these text based editors offer.

4 10 Jul 2015 20:16 u/CirdanValen in v/programming
Comment on: What a C programmer should know about memory

a) you posted nothing proving your claim. It's really not that difficult to manage memory. I've written several data structures in C using malloc/free without much trouble.

b) since we are using psudo proof: Garbage collection breeds lazy and unskilled programmers which leads to aweful software like Batman. Not to mention how awful it is to bounce pointers all over the place raping the cache, and wasting tons of cpu cycles cleaning up and allocating memory whe its not needed.

0 25 Jun 2015 16:26 u/CirdanValen in v/programming
Comment on: What a C programmer should know about memory

Garbage collection is part of the reason software still runs as slow as it did in 1997

3 24 Jun 2015 21:13 u/CirdanValen in v/programming
  • ‹‹‹
  • ‹‹
  • ‹
  • 1
  • ›
  • ››
  • ›››

archive has 9,592 posts and 65,719 comments. source code.