How do you program the SMD ATMega328 IC in an inexpensive way?I know you can get a factory to program the chips but is there a way to program them with Arduino without one of those expensive sockets.
Yes, you put a 6 pin ISCP header on the PCB to support flash programming, buy a $5 USBASP programmer from Ebay, and flash the Arduino program straight to the board, skipping the whole serial/USB bootloader stuff.
I've done this for years now, it's fine. An important thing to note is to use Arduino environment (with the equivalent/reference board, processor, voltage and frequency settings correct for your target board) to flash the bootloader first. This sets all the fuses to ensure the ATMEGA uses the correct clock frequency and other fuse settings which are normally a pain to work through the datasheet/online tables.
After you burn the bootloader, then use the Arduino environment as normal, but select the "Upload with programmer" instead of "Upload" and this will use the USBASP (make sure to select the programmer in the programmer tools options) to flash the program directly to the ATMEGA, rather than the USB bootloader method.
This is great for if your boards do not have USB on them, like for very small projects where it's not needed. Debugging can still be done by using an external serial interface like a FTDI USB-Serial adapter on the ATMEGA's serial pins (which you need to break out to a header somewhere with RX, TX, and GND)
Of course, you can use the official Atmel AVRISP Mk2 or full on JTAG style interface to flash the chip. Either way, your PCB which the SMD IC is going to be soldered on to should have the support for flash programming. If not, add it. As you said, a socket to program out-of-system is not really a good solution. Large scale production runs should indeed be pre-programmed at the factory to avoid all this nonsense - but that is very far down the line for product design. At a prototype level, just put the header on for ISP programming, and serial breakout.