programming-techniques

How do i get out of the habit of procedural programming and into object oriented programming?

Hiya all, I'm hoping to get some tips to kinda help me break out of what i consider after all these years a bad habit of procedural programming. Every time i attempt to do a project in OOP i end up eventually reverting to procedural. I guess i'm not completely convinced with OOP (even though i think i've heard everything good about it...

Is it possible to create a domain model for legacy code without refactoring?

I currently have a client that wants me to 'abstract' out a domain model from the existing code but they specifically said that I shouldn't refactor the existing code itself. My question is 1) whether or not this is advisable and 2) what techniques would you apply in this scenario if you can't refactor the code yet they expect you to com...

Ruby: counters, counting and incrementing

Hi, If you have seen my previous questions, you'd already know I am a big nuby when it comes to Ruby. So, I discovered this website which is intended for C programming, but I thought whatever one can do in C, must be possible in Ruby (and more readable too). The challenge is to print out a bunch of numbers. I discovered this nifty met...

Ruby: Mark an object for garbage collection

Hi, I was wondering if there is a similar .finalize() method for Ruby objects, that marks them ready for garbage collection. If I would create 20,000 objects and each instance has a counter, I would like the object to be marked for garbage collection when reaches zero. I know this is pretty much a Java approach, but I have not sufficien...

Design Technique: How to design a complex system for processing orders, products and units.

Hi, Programming is fun: I learned that by trying out simple challenges, reading up some books and following some tutorials. I am able to grasp the concepts of writing with OO (I do so in Ruby), and write a bit of code myself. What bugs me though is that I feel I'm re-inventing the wheel: I haven't followed an education or found a book ...

Purpose of IF, ELSE, FOR macros ?

I have a source code of a library which has a lot of strange IF, ELSE, FOR, etc. macros for all common C-keywords instead of using just usual if,else,for,while keywords. These macros are defined like this: #define IF( a) if( increment_if(), a) where increment_if() function is defined so: static __inline void increment_if( void) { ...

How to receive packets on the MCU's serial port?

Hello, Consider this code running on my microcontroller unit(MCU): while(1){ do_stuff; if(packet_from_PC) send_data_via_gpio(new_packet); //send via general purpose i/o pins else send_data_via_gpio(default_packet); do_other_stuff; } The MCU is also interfaced to a PC via a UART.Whenever the PC sends data to the MCU, the *n...

What techniques are there to prevent / remove shared state?

Problem Shared state is in certain cases a bad thing. I am in a project right now where pretty much all methods perform some sort of state change. I believe that's a problem. On one hand, I can't reuse the methods because depending on the current system state the new system state after the method call will be different. On the other han...