• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 14:33
CEST 20:33
KST 03:33
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
[ASL21] Ro8 Preview Pt1: Inheritors14[ASL21] Ro16 Preview Pt2: All Star10Team Liquid Map Contest #22 - The Finalists19[ASL21] Ro16 Preview Pt1: Fresh Flow9[ASL21] Ro24 Preview Pt2: News Flash10
Community News
2026 GSL Season 1 Qualifiers22Maestros of the Game 2 announced92026 GSL Tour plans announced15Weekly Cups (April 6-12): herO doubles, "Villains" prevail1MaNa leaves Team Liquid25
StarCraft 2
General
Team Liquid Map Contest #22 - The Finalists MaNa leaves Team Liquid Maestros of the Game 2 announced 2026 GSL Tour plans announced Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool
Tourneys
2026 GSL Season 1 Qualifiers Sparkling Tuna Cup - Weekly Open Tournament INu's Battles#14 <BO.9 2Matches> GSL CK: More events planned pending crowdfunding RSL Revival: Season 5 - Qualifiers and Main Event
Strategy
Custom Maps
[D]RTS in all its shapes and glory <3 [A] Nemrods 1/4 players [M] (2) Frigid Storage
External Content
The PondCast: SC2 News & Results Mutation # 523 Firewall Mutation # 522 Flip My Base Mutation # 521 Memorable Boss
Brood War
General
[ASL21] Ro8 Preview Pt1: Inheritors BGH Auto Balance -> http://bghmmr.eu/ FlaSh: This Will Be My Final ASL【ASL S21 Ro.16】 Leta's ASL S21 Ro.16 review ASL21 General Discussion
Tourneys
[Megathread] Daily Proleagues [ASL21] Ro8 Day 1 [ASL21] Ro16 Group D Escore Tournament StarCraft Season 2
Strategy
Fighting Spirit mining rates Simple Questions, Simple Answers What's the deal with APM & what's its true value Any training maps people recommend?
Other Games
General Games
Dawn of War IV Stormgate/Frost Giant Megathread Diablo IV Nintendo Switch Thread Total Annihilation Server - TAForever
Dota 2
The Story of Wings Gaming
League of Legends
G2 just beat GenG in First stand
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas TL Mafia Community Thread Five o'clock TL Mafia
Community
General
US Politics Mega-thread 3D technology/software discussion European Politico-economics QA Mega-thread Canadian Politics Mega-thread Things Aren’t Peaceful in Palestine
Fan Clubs
The IdrA Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [Req][Books] Good Fantasy/SciFi books Movie Discussion!
Sports
2024 - 2026 Football Thread Formula 1 Discussion McBoner: A hockey love story
World Cup 2022
Tech Support
streaming software Strange computer issues (software) [G] How to Block Livestream Ads
TL Community
The Automated Ban List
Blogs
Sexual Health Of Gamers
TrAiDoS
lurker extra damage testi…
StaticNine
Broowar part 2
qwaykee
Funny Nicknames
LUCKY_NOOB
Iranian anarchists: organize…
XenOsky
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2640 users

The Big Programming Thread - Page 414

Forum Index > General Forum
Post a Reply
Prev 1 412 413 414 415 416 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Cyx.
Profile Joined November 2010
Canada806 Posts
December 27 2013 07:32 GMT
#8261
On December 27 2013 13:24 WarSame wrote:
What is the 100x better? I went through my original code and improved it a lot based off of his comments, so could you do the same thing? There was nothing that struck me as obviously bad, so there's really nothing left for me to catch for myself.

Anyway... the sad thing is I'm in 3rd year Software Engineering. Finally starting to actually use my free time to program.

Well, let me start by saying that I don't do a lot of Java (my school is mostly C++), but I'll point out some of the language-agnostic things I feel could be managed a lot better.

First: your files are WAY too big. Each class should have its own file (I'm looking at you, MouseHandler), and there is DEFINITELY too much in your TicTacToePanel class.

First thing I would do is factor out all that AI code in two ways. One, put it in its own file, in its own class - as it is, I can't tell what that class is responsible for at all. On first glance I would assume it's a UI element since it implements JPanel - but there's a SHITLOAD of logic in there that's not at all connected to that, and someone reading your code really has to read every single method definition pretty in-depth in order to understand what the class is responsible for. So write a new class - and name it something that makes sense. Classes should only be responsible for a fairly coherent set of functionality - they're not just containers for you to toss methods and data into (well, they actually ARE but you shouldn't do that! =D).

Second thing I'd do to the AI code is break it down into like five functions. As it is, like above, someone actually has to read through every single line of the method definition in order to understand what's happening - that's not good. Anyone looking at your class should be able to get a pretty good idea of what it does just by reading the method names and parameters - going deep into the methods in order to understand them takes time and frustration and you're also never sure you got it right.

So as a general rule of thumb - if your girlfriend/mom/technically retarded roommate or whatever can't get the gist of everything that method does just by you reading the name of it to them, you've done something wrong. Split it up a bit into some smaller functions. Some people (HI SLUGGASLAMMOOOOO) will tell you that every method should have less than 5 lines of code or something - I do feel like that's pretty extreme but the idea is REALLY solid. Make your code easy to understand - and that means organizing it into small, neat chunks.

You're guilty of the same thing in your checkVictory function - in fact, all of the logic that actually controls how the game works is just scattered wickedly over your three classes. This (I guess? I don't know the idea that well but from what I have seen in the thread so far) would bring you a LOT closer to that MVC setup everyone's been talking about - you should have a separate class to CONTROL everything, for the same reasons as given above.

So basically, without digging into the Java-specific stuff too much - your functions AND classes are DISGUSTINGLY huge and almost impossible for anyone to read without struggling through it line by line. Make your functions smaller, and make your classes responsible for a coherent set of functionality - one class does AI, one class does drawing the board, one class handles user input, and one class checks victory conditions (for example).

Other people can probably give you some Java specific advice ^^
IronManSC
Profile Blog Joined November 2010
United States2119 Posts
December 27 2013 07:50 GMT
#8262
lynda.com is a fantastic website for any designer, developer, or programmer. I think it's $20/mo but believe me, it's well worth it. I'm currently good at html5 and css3, and am running through tutorials for javascripting, and lynda.com is amazingly helpful and easy to understand.
SC2 Mapmaker || twitter: @ironmansc || Ohana & Mech Depot || 3x TLMC finalist || www.twitch.tv/sc2mapstream
berated-
Profile Blog Joined February 2007
United States1134 Posts
Last Edited: 2013-12-27 12:25:51
December 27 2013 12:21 GMT
#8263
On December 27 2013 13:24 WarSame wrote:
What is the 100x better? I went through my original code and improved it a lot based off of his comments, so could you do the same thing? There was nothing that struck me as obviously bad, so there's really nothing left for me to catch for myself.

Anyway... the sad thing is I'm in 3rd year Software Engineering. Finally starting to actually use my free time to program.


I think he's a magician to find 100x improvement. Judging from his other posts I think at least 90x improvement would come from moving it out of java.

From my personal experience, learning the improvements being suggested isn't something that you're just going to kind of pick up from someone telling you. Everyone harps on single responsibility and readability, but when you first start (and still in Uni is definitely still way early) I always struggled to find the _why_ of these suggestions. The software works, and you wrote it from scratch so you know where everything is // what it does -- so what's the big deal, right?

Then I started unit testing... When you first try to use your own apis, it's amazing how much they suck -- mine were awful. Writing tests allows for you to to kind of become the first consumer of your software, which is a great perspective into how you should write your code. It's also great documentation to others as to how you expect the code to be used.

So, maybe you're way better at all this stuff than I am and can take these suggestions and make it better -- but if not, try writing some tests to prove that your code works. It takes a good amount of time to get better at writing tests as well, but, if you start now you'll have a great jump on a lot of the other people graduating with you.
sluggaslamoo
Profile Blog Joined November 2009
Australia4494 Posts
December 27 2013 13:39 GMT
#8264
On December 27 2013 21:21 berated- wrote:
Show nested quote +
On December 27 2013 13:24 WarSame wrote:
What is the 100x better? I went through my original code and improved it a lot based off of his comments, so could you do the same thing? There was nothing that struck me as obviously bad, so there's really nothing left for me to catch for myself.

Anyway... the sad thing is I'm in 3rd year Software Engineering. Finally starting to actually use my free time to program.


I think he's a magician to find 100x improvement. Judging from his other posts I think at least 90x improvement would come from moving it out of java.

From my personal experience, learning the improvements being suggested isn't something that you're just going to kind of pick up from someone telling you. Everyone harps on single responsibility and readability, but when you first start (and still in Uni is definitely still way early) I always struggled to find the _why_ of these suggestions. The software works, and you wrote it from scratch so you know where everything is // what it does -- so what's the big deal, right?

Then I started unit testing... When you first try to use your own apis, it's amazing how much they suck -- mine were awful. Writing tests allows for you to to kind of become the first consumer of your software, which is a great perspective into how you should write your code. It's also great documentation to others as to how you expect the code to be used.

So, maybe you're way better at all this stuff than I am and can take these suggestions and make it better -- but if not, try writing some tests to prove that your code works. It takes a good amount of time to get better at writing tests as well, but, if you start now you'll have a great jump on a lot of the other people graduating with you.


A good player does not blame his equipment.

Even if they endlessly harp on which equipment is superior.
Come play Android Netrunner - http://www.teamliquid.net/forum/viewmessage.php?topic_id=409008
sluggaslamoo
Profile Blog Joined November 2009
Australia4494 Posts
Last Edited: 2013-12-28 06:07:17
December 27 2013 19:24 GMT
#8265
On December 27 2013 13:24 WarSame wrote:
What is the 100x better? I went through my original code and improved it a lot based off of his comments, so could you do the same thing? There was nothing that struck me as obviously bad, so there's really nothing left for me to catch for myself.

Anyway... the sad thing is I'm in 3rd year Software Engineering. Finally starting to actually use my free time to program.


I quickly hacked up my own version instead, have a look. I decided to just upload the full netbeans project, makes it easier.

https://github.com/DanielShuey/Java-TicTacToe-Example

The AI just picks random cells, but I don't really have the time to do a full port and you should be able to implement it yourself by creating a new AI class and extending Player.

It should be easily extensible, and you should be able to make the board any size (e.g 3x3, 5x5, etc) but I haven't tested anything more than 3x3.

There's no 2D array by the way, because it doesn't need one and it makes the algorithms much simpler this way. I just have a single list for all cells. See if you can figure out how I did it.

This is the main body of the code where I check the result and see if it has been solved.


private void checkResults() {
for(List<Cell> row : board.getAllRowsAndColumns())
if(rowSolved(row))
winner = currentPlayer;
}

private boolean rowSolved(List<Cell> row) {
Player player = row.get(0).player;

if(player == null)
return false;

for(Cell c : row)
if(c.player != player)
return false;

return true;
}


Also I didn't use MVC, just stuck to the basics, functional decomposition, object decomposition, generalisation-specialisation.

For all the haters
Excludes empty lines, empty methods.

File Lines/Method Avg
Board.java 7+2+1+8+4+4+4+4+4+2+1 3.7
Cell.java 2+5+1+1 2.25
RandomAI.java 1+1+5 2.3
Game.java 5+1+5+3+7+3+2+2 3.5
Player.java 1 1
HumanPlayer.java 1+3+1+3 2
Main.java 1 1

Total average lines per method = 2.97


So much for impossible... ah fuggetaboutit

Come play Android Netrunner - http://www.teamliquid.net/forum/viewmessage.php?topic_id=409008
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
December 27 2013 19:40 GMT
#8266
On December 27 2013 16:50 IronManSC wrote:
lynda.com is a fantastic website for any designer, developer, or programmer. I think it's $20/mo but believe me, it's well worth it. I'm currently good at html5 and css3, and am running through tutorials for javascripting, and lynda.com is amazingly helpful and easy to understand.


I'll second this recommendation.
Any sufficiently advanced technology is indistinguishable from magic
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
December 27 2013 19:47 GMT
#8267
On December 28 2013 04:24 sluggaslamoo wrote:
For all the haters
Excludes empty lines, empty methods.

File Lines/Method Avg
Board.java 7+2+1+8+4+4+4+4+4+2+1 3.7
Cell.java 2+5+1+1 2.25
RandomAI.java 1+1+5 2.3
Game.java 5+1+5+3+7+3+2+2 3.5
Player.java 1 1
HumanPlayer.java 1+3+1+3 2
Main.java 1 1

Total average lines per method = 1.97

2.97

No cheating. Pretty code though.
If you have a good reason to disagree with the above, please tell me. Thank you.
sluggaslamoo
Profile Blog Joined November 2009
Australia4494 Posts
Last Edited: 2013-12-27 19:54:09
December 27 2013 19:53 GMT
#8268
On December 28 2013 04:47 spinesheath wrote:
Show nested quote +
On December 28 2013 04:24 sluggaslamoo wrote:
For all the haters
Excludes empty lines, empty methods.

File Lines/Method Avg
Board.java 7+2+1+8+4+4+4+4+4+2+1 3.7
Cell.java 2+5+1+1 2.25
RandomAI.java 1+1+5 2.3
Game.java 5+1+5+3+7+3+2+2 3.5
Player.java 1 1
HumanPlayer.java 1+3+1+3 2
Main.java 1 1

Total average lines per method = 1.97

2.97

No cheating. Pretty code though.


2.25, I accidentally divided by 8 instead of 7

Still destroys the 3-5 lines recommendation that I gave that certain people told me was impossible. T_T
Come play Android Netrunner - http://www.teamliquid.net/forum/viewmessage.php?topic_id=409008
Yoshi-
Profile Joined October 2008
Germany10227 Posts
Last Edited: 2013-12-27 20:27:21
December 27 2013 20:16 GMT
#8269
On December 28 2013 04:53 sluggaslamoo wrote:


Still destroys the 3-5 lines recommendation that I gave that certain people told me was impossible. T_T


Are you trolling or that stupid?

You said sth among the lines "your functions shouldn't be longer than 3-5 lines", and not "the average length of your function should be around 3-5 lines", if you write a getter/setter for every variable you obviously get an extremely low average.

In many if/while expression you didn't used the brackets(which many people would most probably consider to be bad), if you would have written it in the "proper way" or if you ever need to add another statement to those structure, it would obviously inflate your average.
If you would have used a different coding style like Allman, it would also have increased your line count.


So yea your 3-5 lines recommendation is bullshit, since you 1) weren't talking about averages and 2) it heavily depends on the coding style.

Or you used the ternary operator, many people would have used a normal if structure instead, since those are much easier to understand at the first look, but obviously much longer.

And you were also saying that you shouldn't repeat yourself.

public List<Cell> getColumn(int columnNumber) {
List<Cell> row = new ArrayList();
for(int i = 0; i < widthTiles; i++)
row.add(getCell(columnNumber, i));
return row;
}

public List<Cell> getDiagonalRowTop() {
List<Cell> row = new ArrayList();
for(int i = 0; i < widthTiles; i++)
row.add(getCell(i, i));
return row;
}

public List<Cell> getDiagonalRowBottom() {
List<Cell> row = new ArrayList();
for(int i = 0; i < widthTiles; i++)
row.add(getCell(i, widthTiles-i-1));
return row;
}
mihajovics
Profile Joined April 2011
179 Posts
Last Edited: 2013-12-27 20:26:08
December 27 2013 20:21 GMT
#8270
I'm in academia (linguistics) and I want to learn to code. I'm drifting towards a computer sciencey part of my field. Everybody's first recommendation is to learn python because you can do quick mockups, there are lots of existing libraries, etc.
But I feel like on the long run I should learn C and some Computer Science in general (especially the math behind algorithms, etc).
I'd be interested in some feedback.
Thank you.

EDIT: I have a basic background in C and python already, but I want to break out of the "look up every second command and syntax from the tutorial while coding" phase
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
December 27 2013 20:33 GMT
#8271
On December 28 2013 04:53 sluggaslamoo wrote:
Show nested quote +
On December 28 2013 04:47 spinesheath wrote:
On December 28 2013 04:24 sluggaslamoo wrote:
For all the haters
Excludes empty lines, empty methods.

File Lines/Method Avg
Board.java 7+2+1+8+4+4+4+4+4+2+1 3.7
Cell.java 2+5+1+1 2.25
RandomAI.java 1+1+5 2.3
Game.java 5+1+5+3+7+3+2+2 3.5
Player.java 1 1
HumanPlayer.java 1+3+1+3 2
Main.java 1 1

Total average lines per method = 1.97

2.97

No cheating. Pretty code though.


2.25, I accidentally divided by 8 instead of 7

Still destroys the 3-5 lines recommendation that I gave that certain people told me was impossible. T_T

Well, now you look a bit stupid :p You just averaged over the averages. Which is quite the blunder mathematically; I don't think I have to explain why.


Counting actual lines of text is a bad idea anyways. Complexity comes from number of operations/instructions and other stuff. Which is why the common code metric "lines of code" usually doesn't count actual lines of text.
If you have a good reason to disagree with the above, please tell me. Thank you.
Millitron
Profile Blog Joined August 2010
United States2611 Posts
December 27 2013 20:40 GMT
#8272
On December 28 2013 05:21 mihajovics wrote:
I'm in academia (linguistics) and I want to learn to code. I'm drifting towards a computer sciencey part of my field. Everybody's first recommendation is to learn python because you can do quick mockups, there are lots of existing libraries, etc.
But I feel like on the long run I should learn C and some Computer Science in general (especially the math behind algorithms, etc).
I'd be interested in some feedback.
Thank you.

EDIT: I have a basic background in C and python already, but I want to break out of the "look up every second command and syntax from the tutorial while coding" phase

I would talk to your school's CS department, and see if you could take Principles of Programming Languages and Theory of Computation, or whatever they're called at your school. Those are the two courses that involve the most linguistics stuff. You might have to take an Algorithms course as a prereq for Theory of Comp. If you're only interested in CS for the linguistics, you don't really need to learn any more coding than these courses require.

If these courses aren't really an option, I highly recommend "Introduction to Theory of Computation" by Sipser. Great textbook, covers theory of comp really well, and a little PPL.
Who called in the fleet?
Cyx.
Profile Joined November 2010
Canada806 Posts
Last Edited: 2013-12-27 21:38:13
December 27 2013 21:37 GMT
#8273
On December 28 2013 05:16 Yoshi- wrote:
Show nested quote +
On December 28 2013 04:53 sluggaslamoo wrote:


Still destroys the 3-5 lines recommendation that I gave that certain people told me was impossible. T_T


Are you trolling or that stupid?

You said sth among the lines "your functions shouldn't be longer than 3-5 lines", and not "the average length of your function should be around 3-5 lines", if you write a getter/setter for every variable you obviously get an extremely low average.


Holy shit lol... can we all get over the stupidly pedantic discussion of whether or not you REALLY ACTUALLY NEED EXACTLY FIVE LINES OF CODE PER METHOD OMFG and just agree that having your functions be pretty small is unarguably a good thing? Like, even if slugg isn't exactly perfect, and even if he did his averaging a little bit wrong, and even if he WAS a bit uptight about it when he first started talking about it, everything he says is still totally true. Having 100-line-long functions is absolutely HORRIBLE for readability, and if you can break that down into 10 10-line functions, then I just don't see how that could POSSIBLY be a bad thing.

Even if you want to PM slugg and flame him like he's the fucking devil himself, can we at least agree to tell the people who are asking for help that all the clean-code ideas he advocates are pretty damn good ideas?

e: I guess all I'm saying is - try to keep it clear in your head whether you're HELPING SOMEONE or HAVING A SHITTY LITTLE ARGUMENT OVER SOMETHING SOMEONE SAID FIVE PAGES AGO. And if it's the latter, use PMs. That's what they're for.
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2013-12-27 22:13:47
December 27 2013 22:06 GMT
#8274
On December 28 2013 05:21 mihajovics wrote:
I'm in academia (linguistics) and I want to learn to code. I'm drifting towards a computer sciencey part of my field. Everybody's first recommendation is to learn python because you can do quick mockups, there are lots of existing libraries, etc.
But I feel like on the long run I should learn C and some Computer Science in general (especially the math behind algorithms, etc).
I'd be interested in some feedback.
Thank you.

EDIT: I have a basic background in C and python already, but I want to break out of the "look up every second command and syntax from the tutorial while coding" phase


What do you need coding for? C is low level and not that strongly typed language. My advice is to try a higher level language such as C#/Java/Objective-C. There are many more though but those are close to the C family. possibly excluding Objective-C. Its syntax doesn't remind me of the C style too much.

Edit: It looks like it's considered to be part of it which I don't agree too much with. Although C can be used within Objective-C, Objective-C itself has... a different style?

C family: http://en.wikipedia.org/wiki/Category:C_programming_language_family
mihajovics
Profile Joined April 2011
179 Posts
December 28 2013 00:06 GMT
#8275
On December 28 2013 05:40 Millitron wrote:
Show nested quote +
On December 28 2013 05:21 mihajovics wrote:
I'm in academia (linguistics) and I want to learn to code. I'm drifting towards a computer sciencey part of my field. Everybody's first recommendation is to learn python because you can do quick mockups, there are lots of existing libraries, etc.
But I feel like on the long run I should learn C and some Computer Science in general (especially the math behind algorithms, etc).
I'd be interested in some feedback.
Thank you.

EDIT: I have a basic background in C and python already, but I want to break out of the "look up every second command and syntax from the tutorial while coding" phase

I would talk to your school's CS department, and see if you could take Principles of Programming Languages and Theory of Computation, or whatever they're called at your school. Those are the two courses that involve the most linguistics stuff. You might have to take an Algorithms course as a prereq for Theory of Comp. If you're only interested in CS for the linguistics, you don't really need to learn any more coding than these courses require.

If these courses aren't really an option, I highly recommend "Introduction to Theory of Computation" by Sipser. Great textbook, covers theory of comp really well, and a little PPL.


I mainly need to code relatively simple, practical tasks, like grammar parsers, etc. to generate (or examine already existing) data... These vary a lot in the specifics, but in general all involve some simple database structure (tokenized text).
I guess for these kinds of tasks python is great, because it's fast (to code and learn) and has a lot of out of the box solutions to fall back on.

My aversion though stems from feeling like a cop out. The thing is that some newer theories are shifting towards "bigger picture" methods that involve stuff like neural networks, etc. So computational efficiency (might) actually start to matter. It just feels like that learning C would help one to grasp this whole "computer thing" so to say, how things actually work, and I guess that would help in all sorts of ways. Am I wrong on this?

The other part I need to know, CS, I understand is basically completely separate from coding. It's the concepts behind several different technical implementations. Thanks for the tips, I'll sniff around for some classes next semester and till then I'll check out the book you recommended.
Millitron
Profile Blog Joined August 2010
United States2611 Posts
Last Edited: 2013-12-28 00:42:13
December 28 2013 00:40 GMT
#8276
On December 28 2013 09:06 mihajovics wrote:
Show nested quote +
On December 28 2013 05:40 Millitron wrote:
On December 28 2013 05:21 mihajovics wrote:
I'm in academia (linguistics) and I want to learn to code. I'm drifting towards a computer sciencey part of my field. Everybody's first recommendation is to learn python because you can do quick mockups, there are lots of existing libraries, etc.
But I feel like on the long run I should learn C and some Computer Science in general (especially the math behind algorithms, etc).
I'd be interested in some feedback.
Thank you.

EDIT: I have a basic background in C and python already, but I want to break out of the "look up every second command and syntax from the tutorial while coding" phase

I would talk to your school's CS department, and see if you could take Principles of Programming Languages and Theory of Computation, or whatever they're called at your school. Those are the two courses that involve the most linguistics stuff. You might have to take an Algorithms course as a prereq for Theory of Comp. If you're only interested in CS for the linguistics, you don't really need to learn any more coding than these courses require.

If these courses aren't really an option, I highly recommend "Introduction to Theory of Computation" by Sipser. Great textbook, covers theory of comp really well, and a little PPL.


I mainly need to code relatively simple, practical tasks, like grammar parsers, etc. to generate (or examine already existing) data... These vary a lot in the specifics, but in general all involve some simple database structure (tokenized text).
I guess for these kinds of tasks python is great, because it's fast (to code and learn) and has a lot of out of the box solutions to fall back on.

My aversion though stems from feeling like a cop out. The thing is that some newer theories are shifting towards "bigger picture" methods that involve stuff like neural networks, etc. So computational efficiency (might) actually start to matter. It just feels like that learning C would help one to grasp this whole "computer thing" so to say, how things actually work, and I guess that would help in all sorts of ways. Am I wrong on this?

The other part I need to know, CS, I understand is basically completely separate from coding. It's the concepts behind several different technical implementations. Thanks for the tips, I'll sniff around for some classes next semester and till then I'll check out the book you recommended.

Theory of Computation will have you work with the three big kinds of automata. Finite State Machines, Push-down Automata (also known as grammars), and Turing Machines. You'll learn what kinds of things each can and cannot compute, you'll definitely code a few FSM's and grammars, and you'll probably also code a few Turing Machines. My personal favorite parts of the class were when we had to code "simulators" for each kind of automaton. At the end of discussing one kind of automata, the prof would give us a file structure describing that automaton, and we had to code a simulator which would read the file, parse out the definitions of that particular automaton, and run it. For instance, for FSM's, the file would contain a list of states, a list of transitions, a start state, end states, and one or more sets of input. Our sim would read the file, build the FSM, and run it on the given input(s). The prof had a bunch of different finite state machines following the same format, which he would use to test our simulators. The FSM version of the assignment is pretty easy, its not much more than a linked list, but it can get pretty complicated for Push-down Automata and Turing Machines.

I would say that any language will give you some idea of how computers work. C will show you the nitty-gritty details, while say python or java will hide the minute details and do a better job showing you the bigger picture. I don't really know anything about neural networks, suffice to say you will probably want to pick a language that focuses on parallelism, considering that, if my understanding is correct, each neuron is a simple computer, and they're all running simultaneously.

Principles of Programming Languages should cover the concepts behind the technical implementations you mentioned. Unless by "technical implementations" you meant your PC, in which case you'll want to take Systems.
Who called in the fleet?
mihajovics
Profile Joined April 2011
179 Posts
December 28 2013 01:46 GMT
#8277
On December 28 2013 09:40 Millitron wrote:
Show nested quote +
On December 28 2013 09:06 mihajovics wrote:
On December 28 2013 05:40 Millitron wrote:
On December 28 2013 05:21 mihajovics wrote:
I'm in academia (linguistics) and I want to learn to code. I'm drifting towards a computer sciencey part of my field. Everybody's first recommendation is to learn python because you can do quick mockups, there are lots of existing libraries, etc.
But I feel like on the long run I should learn C and some Computer Science in general (especially the math behind algorithms, etc).
I'd be interested in some feedback.
Thank you.

EDIT: I have a basic background in C and python already, but I want to break out of the "look up every second command and syntax from the tutorial while coding" phase

I would talk to your school's CS department, and see if you could take Principles of Programming Languages and Theory of Computation, or whatever they're called at your school. Those are the two courses that involve the most linguistics stuff. You might have to take an Algorithms course as a prereq for Theory of Comp. If you're only interested in CS for the linguistics, you don't really need to learn any more coding than these courses require.

If these courses aren't really an option, I highly recommend "Introduction to Theory of Computation" by Sipser. Great textbook, covers theory of comp really well, and a little PPL.


I mainly need to code relatively simple, practical tasks, like grammar parsers, etc. to generate (or examine already existing) data... These vary a lot in the specifics, but in general all involve some simple database structure (tokenized text).
I guess for these kinds of tasks python is great, because it's fast (to code and learn) and has a lot of out of the box solutions to fall back on.

My aversion though stems from feeling like a cop out. The thing is that some newer theories are shifting towards "bigger picture" methods that involve stuff like neural networks, etc. So computational efficiency (might) actually start to matter. It just feels like that learning C would help one to grasp this whole "computer thing" so to say, how things actually work, and I guess that would help in all sorts of ways. Am I wrong on this?

The other part I need to know, CS, I understand is basically completely separate from coding. It's the concepts behind several different technical implementations. Thanks for the tips, I'll sniff around for some classes next semester and till then I'll check out the book you recommended.

Theory of Computation will have you work with the three big kinds of automata. Finite State Machines, Push-down Automata (also known as grammars), and Turing Machines. You'll learn what kinds of things each can and cannot compute, you'll definitely code a few FSM's and grammars, and you'll probably also code a few Turing Machines. My personal favorite parts of the class were when we had to code "simulators" for each kind of automaton. At the end of discussing one kind of automata, the prof would give us a file structure describing that automaton, and we had to code a simulator which would read the file, parse out the definitions of that particular automaton, and run it. For instance, for FSM's, the file would contain a list of states, a list of transitions, a start state, end states, and one or more sets of input. Our sim would read the file, build the FSM, and run it on the given input(s). The prof had a bunch of different finite state machines following the same format, which he would use to test our simulators. The FSM version of the assignment is pretty easy, its not much more than a linked list, but it can get pretty complicated for Push-down Automata and Turing Machines.

I would say that any language will give you some idea of how computers work. C will show you the nitty-gritty details, while say python or java will hide the minute details and do a better job showing you the bigger picture. I don't really know anything about neural networks, suffice to say you will probably want to pick a language that focuses on parallelism, considering that, if my understanding is correct, each neuron is a simple computer, and they're all running simultaneously.

Principles of Programming Languages should cover the concepts behind the technical implementations you mentioned. Unless by "technical implementations" you meant your PC, in which case you'll want to take Systems.


I kind of already studied formal languages and automatons, but I could definitely use a refresh for sure. These approaches were extremely popular in the 60s and 70s for studying language. Really interesting topic! Ultimately all these approaches were unsuccessful, except for some very specific subsets of problems, hence all newer research is based on some sort of statistical, distributional model.

But I'm getting off topic, thanks a lot for the input! I think I'll just go with whatever language has a course I can take.
berated-
Profile Blog Joined February 2007
United States1134 Posts
December 28 2013 03:43 GMT
#8278
On December 28 2013 05:16 Yoshi- wrote:
Show nested quote +
On December 28 2013 04:53 sluggaslamoo wrote:


Still destroys the 3-5 lines recommendation that I gave that certain people told me was impossible. T_T


Are you trolling or that stupid?

You said sth among the lines "your functions shouldn't be longer than 3-5 lines", and not "the average length of your function should be around 3-5 lines", if you write a getter/setter for every variable you obviously get an extremely low average.

In many if/while expression you didn't used the brackets(which many people would most probably consider to be bad), if you would have written it in the "proper way" or if you ever need to add another statement to those structure, it would obviously inflate your average.
If you would have used a different coding style like Allman, it would also have increased your line count.


So yea your 3-5 lines recommendation is bullshit, since you 1) weren't talking about averages and 2) it heavily depends on the coding style.

Or you used the ternary operator, many people would have used a normal if structure instead, since those are much easier to understand at the first look, but obviously much longer.

And you were also saying that you shouldn't repeat yourself.

public List<Cell> getColumn(int columnNumber) {
List<Cell> row = new ArrayList();
for(int i = 0; i < widthTiles; i++)
row.add(getCell(columnNumber, i));
return row;
}

public List<Cell> getDiagonalRowTop() {
List<Cell> row = new ArrayList();
for(int i = 0; i < widthTiles; i++)
row.add(getCell(i, i));
return row;
}

public List<Cell> getDiagonalRowBottom() {
List<Cell> row = new ArrayList();
for(int i = 0; i < widthTiles; i++)
row.add(getCell(i, widthTiles-i-1));
return row;
}
'

You were going strong with the braces point, until... the don't repeat yourself is just a limitation of java imo. What you really want here (I believe) is the equivalent of filtering the list with a closure, but, good luck finding that in java.

I guess you could create an interface that is is like CellFilter that has a single method acceptCell and then have a ColumnCellFilter(int column), TopDiagonalFilter, and BottomDiagonalFilter that is used to filter the list, but I'm thinking that an interface and 3 implementation classes to prevent looping over the same loop 3 times (with separate get cell criteria) probably isn't worth it. Maybe java 8.

I still can't believe everyone is focusing on code complexity and not the fact that he uploaded his project using netbeans.
Zocat
Profile Joined April 2010
Germany2229 Posts
December 28 2013 04:02 GMT
#8279
On December 28 2013 10:46 mihajovics wrote:
Show nested quote +
On December 28 2013 09:40 Millitron wrote:
On December 28 2013 09:06 mihajovics wrote:
On December 28 2013 05:40 Millitron wrote:
On December 28 2013 05:21 mihajovics wrote:
I'm in academia (linguistics) and I want to learn to code. I'm drifting towards a computer sciencey part of my field. Everybody's first recommendation is to learn python because you can do quick mockups, there are lots of existing libraries, etc.
But I feel like on the long run I should learn C and some Computer Science in general (especially the math behind algorithms, etc).
I'd be interested in some feedback.
Thank you.

EDIT: I have a basic background in C and python already, but I want to break out of the "look up every second command and syntax from the tutorial while coding" phase

I would talk to your school's CS department, and see if you could take Principles of Programming Languages and Theory of Computation, or whatever they're called at your school. Those are the two courses that involve the most linguistics stuff. You might have to take an Algorithms course as a prereq for Theory of Comp. If you're only interested in CS for the linguistics, you don't really need to learn any more coding than these courses require.

If these courses aren't really an option, I highly recommend "Introduction to Theory of Computation" by Sipser. Great textbook, covers theory of comp really well, and a little PPL.


I mainly need to code relatively simple, practical tasks, like grammar parsers, etc. to generate (or examine already existing) data... These vary a lot in the specifics, but in general all involve some simple database structure (tokenized text).
I guess for these kinds of tasks python is great, because it's fast (to code and learn) and has a lot of out of the box solutions to fall back on.

My aversion though stems from feeling like a cop out. The thing is that some newer theories are shifting towards "bigger picture" methods that involve stuff like neural networks, etc. So computational efficiency (might) actually start to matter. It just feels like that learning C would help one to grasp this whole "computer thing" so to say, how things actually work, and I guess that would help in all sorts of ways. Am I wrong on this?

The other part I need to know, CS, I understand is basically completely separate from coding. It's the concepts behind several different technical implementations. Thanks for the tips, I'll sniff around for some classes next semester and till then I'll check out the book you recommended.

Theory of Computation will have you work with the three big kinds of automata. Finite State Machines, Push-down Automata (also known as grammars), and Turing Machines. You'll learn what kinds of things each can and cannot compute, you'll definitely code a few FSM's and grammars, and you'll probably also code a few Turing Machines. My personal favorite parts of the class were when we had to code "simulators" for each kind of automaton. At the end of discussing one kind of automata, the prof would give us a file structure describing that automaton, and we had to code a simulator which would read the file, parse out the definitions of that particular automaton, and run it. For instance, for FSM's, the file would contain a list of states, a list of transitions, a start state, end states, and one or more sets of input. Our sim would read the file, build the FSM, and run it on the given input(s). The prof had a bunch of different finite state machines following the same format, which he would use to test our simulators. The FSM version of the assignment is pretty easy, its not much more than a linked list, but it can get pretty complicated for Push-down Automata and Turing Machines.

I would say that any language will give you some idea of how computers work. C will show you the nitty-gritty details, while say python or java will hide the minute details and do a better job showing you the bigger picture. I don't really know anything about neural networks, suffice to say you will probably want to pick a language that focuses on parallelism, considering that, if my understanding is correct, each neuron is a simple computer, and they're all running simultaneously.

Principles of Programming Languages should cover the concepts behind the technical implementations you mentioned. Unless by "technical implementations" you meant your PC, in which case you'll want to take Systems.


I kind of already studied formal languages and automatons, but I could definitely use a refresh for sure. These approaches were extremely popular in the 60s and 70s for studying language. Really interesting topic! Ultimately all these approaches were unsuccessful, except for some very specific subsets of problems, hence all newer research is based on some sort of statistical, distributional model.

But I'm getting off topic, thanks a lot for the input! I think I'll just go with whatever language has a course I can take.


Formal languages & grammars are still important in the CS field. Since our programming languages are based upon those. So if you say to a CS guy "I need to do a grammar parser" they will answer accordingly.

You're probably looking for stuff like language modelling (n-grams) with smoothing (Good-Turing, ....), Katz's back-off ...
Look at Matlab or R. Both have toolboxes.
sluggaslamoo
Profile Blog Joined November 2009
Australia4494 Posts
December 28 2013 04:08 GMT
#8280
On December 28 2013 05:33 spinesheath wrote:
Show nested quote +
On December 28 2013 04:53 sluggaslamoo wrote:
On December 28 2013 04:47 spinesheath wrote:
On December 28 2013 04:24 sluggaslamoo wrote:
For all the haters
Excludes empty lines, empty methods.

File Lines/Method Avg
Board.java 7+2+1+8+4+4+4+4+4+2+1 3.7
Cell.java 2+5+1+1 2.25
RandomAI.java 1+1+5 2.3
Game.java 5+1+5+3+7+3+2+2 3.5
Player.java 1 1
HumanPlayer.java 1+3+1+3 2
Main.java 1 1

Total average lines per method = 1.97

2.97

No cheating. Pretty code though.


2.25, I accidentally divided by 8 instead of 7

Still destroys the 3-5 lines recommendation that I gave that certain people told me was impossible. T_T

Well, now you look a bit stupid :p You just averaged over the averages. Which is quite the blunder mathematically; I don't think I have to explain why.


Counting actual lines of text is a bad idea anyways. Complexity comes from number of operations/instructions and other stuff. Which is why the common code metric "lines of code" usually doesn't count actual lines of text.


2.97 my bad, it was 4am. ;_;

I don't think there was any problem with my reasoning.
Come play Android Netrunner - http://www.teamliquid.net/forum/viewmessage.php?topic_id=409008
Prev 1 412 413 414 415 416 1032 Next
Please log in or register to reply.
Live Events Refresh
Monday Night Weeklies
16:00
#49
RotterdaM1008
TKL 378
IndyStarCraft 236
SteadfastSC221
BRAT_OK 165
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RotterdaM 1008
TKL 369
IndyStarCraft 236
SteadfastSC 221
BRAT_OK 157
UpATreeSC 94
JuggernautJason6
StarCraft: Brood War
Calm 4373
ggaemo 359
Hyun 68
Free 64
Shinee 62
PianO 58
Sexy 33
910 21
HiyA 16
NaDa 6
Dota 2
qojqva4865
capcasts59
Counter-Strike
fl0m2110
pashabiceps1792
byalli1705
Super Smash Bros
Mew2King56
Heroes of the Storm
Khaldor273
Other Games
Grubby4259
B2W.Neo1185
Beastyqt703
ceh9609
Sick234
KnowMe226
C9.Mang0215
mouzStarbuck191
Hui .136
Trikslyr44
MindelVK15
Organizations
Other Games
BasetradeTV379
Dota 2
PGL Dota 2 - Main Stream299
StarCraft: Brood War
Kim Chul Min (afreeca) 7
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 19 non-featured ]
StarCraft 2
• kabyraGe 109
• StrangeGG 81
• Kozan
• LaughNgamezSOOP
• AfreecaTV YouTube
• sooper7s
• intothetv
• Migwel
• IndyKCrew
StarCraft: Brood War
• FirePhoenix25
• 80smullet 13
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• WagamamaTV655
League of Legends
• Nemesis3610
Other Games
• imaqtpie1218
• Shiphtur218
• tFFMrPink 6
Upcoming Events
Replay Cast
5h 27m
Replay Cast
14h 27m
Afreeca Starleague
15h 27m
Leta vs YSC
GSL
1d 14h
Rogue vs Percival
Zoun vs Solar
Replay Cast
2 days
GSL
2 days
Cure vs TriGGeR
ByuN vs Bunny
The PondCast
2 days
KCM Race Survival
2 days
Replay Cast
3 days
Replay Cast
3 days
[ Show More ]
Escore
3 days
Replay Cast
4 days
Replay Cast
4 days
IPSL
4 days
Ret vs Art_Of_Turtle
Radley vs TBD
BSL
5 days
Replay Cast
5 days
uThermal 2v2 Circuit
5 days
BSL
6 days
IPSL
6 days
eOnzErG vs TBD
G5 vs Nesh
Replay Cast
6 days
Wardi Open
6 days
Afreeca Starleague
6 days
Jaedong vs Light
Monday Night Weeklies
6 days
Liquipedia Results

Completed

Escore Tournament S2: W4
WardiTV TLMC #16
Nations Cup 2026

Ongoing

BSL Season 22
ASL Season 21
CSL 2026 SPRING (S20)
IPSL Spring 2026
KCM Race Survival 2026 Season 2
StarCraft2 Community Team League 2026 Spring
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026

Upcoming

Escore Tournament S2: W5
KK 2v2 League Season 1
Acropolis #4
BSL 22 Non-Korean Championship
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
Maestros of the Game 2
2026 GSL S2
RSL Revival: Season 5
2026 GSL S1
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
IEM Atlanta 2026
Asian Champions League 2026
PGL Astana 2026
BLAST Rivals Spring 2026
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.