Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 584 585 [586] 587 588 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 907725 times)

breadman

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8775 on: January 13, 2016, 10:00:09 pm »

Funnily enough, I heard one of the professors at the university here say that we needed to start spending like a month teaching them because nobody knows how to make them anymore.

It took me a bit to understand why it would take a month to teach them.  They're not that complicated in concept.  Then I started realizing what I've actually learned to do with them...

1. Take your shell commands, prepend tabs, and give them a name.
2. Add dependencies.
3. Use variables to condense similar targets into the same rule.
4. Use variables to condense lists of dependencies.
5. Use functions to generate such lists.
6. Generate and cache the actual dependencies for a compiled file, instead of compiling everything every time.
7. #include such a dependency cache file, and ensure that it's included in the dependency lists where necessary.
8. Get the make command to work in subdirectories.
9. The right way, not the industry standard way.
10. Use automake to generate a makefile.
11. Use CMake to generate a makefile.

Is a month really enough, or is it just barely sufficient to get going on what they actually wanted to teach?
Logged
Quote from: Kevin Wayne, in r.g.r.n
Is a "diety" the being pictured by one of those extremely skinny aboriginal statues?

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8776 on: January 13, 2016, 11:59:06 pm »

Pretty much.  I've written a couple of particularly complicated makefiles over the years, and those took a long time to figure out.

These days, I mostly rely on make doing a lot of the work for me, such as automatically building object file dependencies based on the matching source file name.  I shouldn't do that though, since I have had several cases where changes in headers didn't cause relevant things to be rebuilt in all object fiels, causing interesting crashes that took a long time to figure out.

Well made makefiles can reduce the headaches so much.  One thing I've been meaning to do on my current project is to make it easier to swap between release and debug mode.  Right now I have to edit the makefile and change a couple of variables when it really should just be a different build target for each... except that I already have several build targets for different feature sets and I'm not entirely sure how to add release / debug builds with that.

Obviously, I've considered it faster to just change the variables than to look it up and figure it out...
Logged
Through pain, I find wisdom.

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #8777 on: January 14, 2016, 04:29:27 pm »

I've tried multiple times to learn how to make robust makefiles, and I just can't get the hang of it. I'm sure there's a lot I could improve if I just spent the time to learn it, but I usually end up with something like this:

Code: [Select]
SFMLVER := 2.3
OUTD := hexmap-d
OUTR := hexmap
CXXFLAGS += -std=c++11

ifneq ("$(or $(RELEASE),$(R))","")
CXXFLAGS += -O3 -D NDEBUG
OBJDIR := obj/release/
OUT := $(OUTR)
LIB := -lsfml-graphics -lsfml-window -lsfml-system
else
CXXFLAGS += -D _DEBUG -g
OBJDIR := obj/debug/
OUT := $(OUTD)
LIB := -lsfml-graphics-d -lsfml-window-d -lsfml-system-d
endif

SRC := $(wildcard src/*.cpp)
OBJ := $(subst src/,$(OBJDIR), $(subst .cpp,.o, $(SRC)))
INC :=
LIB += -ljsoncpp -lpugixml -lsfgui

.PHONY: all clean

all: $(OBJ)
$(CXX) -o $(OUT) $^ $(LIB)

$(OBJDIR)%.o: src/%.cpp
@mkdir -p -m 777 $(@D)
$(CXX) -c $< -o $@ $(INC) $(CXXFLAGS)

clean:
rm -f $(OUT)
rm -f -rf $(OBJDIR)

And I don't even remember what half of this does.
Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8778 on: January 14, 2016, 05:08:07 pm »

It's been so long since I last wrote a makefile that contained conditions and liberal use of variables that I can't decipher it off hand myself.  It has made me wonder in the past why we don't use more general purpose scripting languages for this though.  Makefiles effectively define a simple scripting language anyway, just with yet another syntax to remember.  Just a legacy from the days where it wasn't practical to expect people to have a script interpreter installed, I guess.

Actually, somewhat unrelatedly, I find it funny that with GNU Make at least, you have to use tab characters when writing the makefile (unless it has some option to switch to spaces).  That was a nice way for me to recognize that my editor was accidentally set to insert spaces instead of tabs once.
Logged
Through pain, I find wisdom.

jaked122

  • Bay Watcher
  • [PREFSTRING:Lurker tendancies]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8779 on: January 14, 2016, 08:09:37 pm »

Wow, everyone I've talked to at the Computer Science courses at RPI complains about people who use tabs instead of spaces...


I think that gnu make might be able to handle spaces now...
set
Code: [Select]
.RECIPEPREFIX = '   '
And that should do it.



They added a new variable for this sort of thing in June 2010.[/code]

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8780 on: January 14, 2016, 08:17:16 pm »

Tabs vs. spaces is nearly religion, depending on who you talk to.  Most people seem to prefer spaces but I prefer tabs pretty much for the reasons they prefer spaces.

I hate modifying code that has been tabinated using 2 spaces instead of the 4 space tabs I'm used to.  At least with tabs you can adjust it in your editor to look like whatever you want without modifying the source itself.
Logged
Through pain, I find wisdom.

jaked122

  • Bay Watcher
  • [PREFSTRING:Lurker tendancies]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8781 on: January 14, 2016, 09:16:12 pm »

I've always observed that many modern editors, maybe not vim or emacs allow such things to be substituted on the fly and viewed as though the four spaces was a tab of your preference. I don't have a preference generally, I'll indent to my satisfaction then run the code through a beautifier.


I don't like handling that myself beyond making the code readable while I write it, the tools can fix it, so why should I do so?


Edit: Python hates tabs. That's why a lot of people don't like it. Because of one language that couldn't be arsed to use proper delimiters, which isn't so bad in itself, has caused real tab characters to clash wherever it comes up.


I don't write python, but hey, tab versus spaces is not a preference if you do.

TheDarkStar

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8782 on: January 14, 2016, 09:20:41 pm »

Tab is love, tab is life. What is this "space" thing that the heathens use?

Edit: Admittedly, the compiler I use automatically turns tabs into spaces.
Logged
Don't die; it's bad for your health!

it happened it happened it happen im so hyped to actually get attacked now

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #8783 on: January 14, 2016, 09:23:51 pm »

I would be interested in a good argument for spaces over tabs, because I just don't see the benefit of using spaces. The only reason you should ever be messing with source code is because you want to change what it does, not that you need to change how it looks. I get the feeling it has more to do with OSes historically freaking the fuck out if they find tabs in text files, causing this superstitious aversion to tabs.
Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8784 on: January 14, 2016, 09:25:04 pm »

spaces will always look consistent between various applications

for example, on b12 here tabs are 8 spaces and in notepad++ they're 4

so i just go with 4 spaces

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8785 on: January 14, 2016, 09:25:59 pm »

Indeed.
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

Bauglir

  • Bay Watcher
  • Let us make Good
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8786 on: January 14, 2016, 09:33:36 pm »

Odd, I've never had problems with it in Python, but then again I always type tabs (regardless of language), but both IDLE and PyCharm seem to conform them to being 4 spaces. If memory serves.
Logged
In the days when Sussman was a novice, Minsky once came to him as he sat hacking at the PDP-6.
“What are you doing?”, asked Minsky. “I am training a randomly wired neural net to play Tic-Tac-Toe” Sussman replied. “Why is the net wired randomly?”, asked Minsky. “I do not want it to have any preconceptions of how to play”, Sussman said.
Minsky then shut his eyes. “Why do you close your eyes?”, Sussman asked his teacher.
“So that the room will be empty.”
At that moment, Sussman was enlightened.

jaked122

  • Bay Watcher
  • [PREFSTRING:Lurker tendancies]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8787 on: January 14, 2016, 10:22:13 pm »

Odd, I've never had problems with it in Python, but then again I always type tabs (regardless of language), but both IDLE and PyCharm seem to conform them to being 4 spaces. If memory serves.
Yes, but spaces are generally converted, pass it -t or -tt to see what you're actually getting.

eerr

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8788 on: January 14, 2016, 11:05:59 pm »

I think I figured out those problems I had with swing/javax/java gui junk(whatever?).

I was supposed to let public static void main complete so the UI thread could take over...

Instead I managed to write blocking code waiting for a UI thread that never completes.

All because I kept assuming the UI ran on a separate thread, having forgotten the earlier examples from OOP class.

#notconcurrent

I just answered my own question.http://www.leepoint.net/JavaBasics/gui/gui-commentary/guicom-main-thread.html
Logged

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8789 on: January 14, 2016, 11:54:29 pm »

I like tabs because I hate having to count one-two-three-four spaces every time I indent, or when my code is slightly misaligned because I miscounted somewhere and I have to redo the entire thing to make sure that it's all correct, but it still looks weird in a way that I can't quite put my finger on and I think maybe it's because there's some sort of weird psychosomatic thing with the font, but then I realize that I've been using spaces in this file and tabs in another file so I have to either redo the tabs file or the spaces file, but I just noticed that I accidentally used one too many spaces in a block that's indented three levels so I backspace just once but GMS's IDE automatically unindents the entire block and aaaaaaaaaaaaaaaaaaaaaaaaaaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

So I use tabs.
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.
Pages: 1 ... 584 585 [586] 587 588 ... 796