• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 03:36
CET 09:36
KST 17:36
  • 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
RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10
Community News
Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2BGE Stara Zagora 2026 announced15[BSL21] Ro.16 Group Stage (C->B->A->D)4Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win3RSL Season 3: RO16 results & RO8 bracket13
StarCraft 2
General
Maestros of the Game: Live Finals Preview (RO4) BGE Stara Zagora 2026 announced Weekly Cups (Nov 24-30): MaxPax, Clem, herO win SC2 Proleague Discontinued; SKT, KT, SGK, CJ disband Information Request Regarding Chinese Ladder
Tourneys
$5,000+ WardiTV 2025 Championship Constellation Cup - Main Event - Stellar Fest RSL Revival: Season 3 Tenacious Turtle Tussle [Alpha Pro Series] Nice vs Cure
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 502 Negative Reinforcement Mutation # 501 Price of Progress Mutation # 500 Fright night Mutation # 499 Chilling Adaptation
Brood War
General
Which season is the best in ASL? [ASL20] Ask the mapmakers — Drop your questions BW General Discussion FlaSh's Valkyrie Copium BGH Auto Balance -> http://bghmmr.eu/
Tourneys
[Megathread] Daily Proleagues [BSL21] RO16 Group B - Sunday 21:00 CET [BSL21] RO16 Group C - Saturday 21:00 CET Small VOD Thread 2.0
Strategy
Game Theory for Starcraft How to stay on top of macro? Current Meta PvZ map balance
Other Games
General Games
Stormgate/Frost Giant Megathread The Perfect Game Path of Exile Nintendo Switch Thread Should offensive tower rushing be viable in RTS games?
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
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
Mafia Game Mode Feedback/Ideas TL Mafia Community Thread
Community
General
Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine US Politics Mega-thread The Big Programming Thread Artificial Intelligence Thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
[Manga] One Piece Movie Discussion! Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Where to ask questions and add stream? The Automated Ban List
Blogs
James Bond movies ranking - pa…
Topin
Esports Earnings: Bigger Pri…
TrAiDoS
Thanks for the RSL
Hildegard
Saturation point
Uldridge
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1224 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
Next event in 3h 24m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
SortOf 202
ProTech117
StarCraft: Brood War
Horang2 2499
actioN 725
Larva 250
Zeus 188
Hyun 138
PianO 112
Sharp 67
Dewaltoss 57
soO 37
NotJumperer 26
[ Show more ]
Hm[arnc] 8
Dota 2
XaKoH 463
XcaliburYe90
League of Legends
JimRising 581
C9.Mang0285
Counter-Strike
shoxiejesuss356
Super Smash Bros
Westballz18
Other Games
summit1g13005
WinterStarcraft572
Happy345
Organizations
Other Games
gamesdonequick701
StarCraft: Brood War
UltimateBattle 85
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• Berry_CruncH236
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• lizZardDota212
League of Legends
• Lourlo1139
• Stunt519
Upcoming Events
Wardi Open
3h 24m
StarCraft2.fi
8h 24m
Replay Cast
15h 24m
The PondCast
1d 1h
OSC
1d 7h
Demi vs Mixu
Nicoract vs TBD
Babymarine vs MindelVK
ForJumy vs TBD
Shameless vs Percival
Replay Cast
1d 15h
Korean StarCraft League
2 days
CranKy Ducklings
3 days
SC Evo League
3 days
BSL 21
3 days
Sziky vs OyAji
Gypsy vs eOnzErG
[ Show More ]
OSC
3 days
Solar vs Creator
ByuN vs Gerald
Percival vs Babymarine
Moja vs Krystianer
EnDerr vs ForJumy
sebesdes vs Nicoract
Sparkling Tuna Cup
4 days
OSC
4 days
BSL 21
4 days
Bonyth vs StRyKeR
Tarson vs Dandy
Replay Cast
5 days
Wardi Open
5 days
StarCraft2.fi
5 days
Replay Cast
5 days
StarCraft2.fi
6 days
PiGosaur Monday
6 days
Liquipedia Results

Completed

Proleague 2025-11-30
RSL Revival: Season 3
Light HT

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
YSL S2
BSL Season 21
CSCL: Masked Kings S3
Slon Tour Season 2
Acropolis #4 - TS3
META Madness #9
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
Kuram Kup
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
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 © 2025 TLnet. All Rights Reserved.