• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 15:48
CEST 21:48
KST 04:48
  • 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
Serral wins HomeStory Cup 2914Serral wins Maestros of the Game 243ByuL, and the Limitations of Standard Play3Team Liquid Map Contest #22: Results and Winners7Code S Season 2 (2026): RO4 and Finals Preview12
Community News
Balance hotfix patch 5.0.16b (July 16)29Reynor: GSL Loss Wasn't About Preparation Format16[IPSL] Spring 2026 Grand Finals - This Weekend!5Weekly Cups (July 6 - 12): Protoss strike back12BSL Season 22 Full Overview & Conclusion8
StarCraft 2
General
Balance hotfix patch 5.0.16b (July 16) [D] Wireframe Casting Removed Clem: "I don't have that much hope in Blizzard" Reynor: GSL Loss Wasn't About Preparation Format Is the larve respawn broken?
Tourneys
Master Swan Open (Global Bronze-Master 2) WardiTV Summer Cup 2026 GSL CK #5 Race War RSL Revival: Season 6 - Qualifiers and Main Event HomeStory Cup 29
Strategy
[G] Having the right mentality to improve
Custom Maps
New Map Maker - Looking for Advice - Love or Hate Work In Progress Melee Maps [D]RTS in all its shapes and glory <3
External Content
The PondCast: SC2 News & Results Mutation # 534 Burning Evacuation Mutation # 533 Die Together Mutation # 532 Nuclear Family
Brood War
General
BW General Discussion Recent recommended BW games Recommended FPV games (post-KeSPA) Etiquete rules in Asl? Pros Debate: Zerg Unfairly Nerfed? (ASL S22 map)
Tourneys
Escore Tournament - Season 3 Small VOD Thread 2.0 [IPSL] Spring 2026 Grand Finals - This Weekend! [Megathread] Daily Proleagues
Strategy
Fighting Spirit mining rates Simple Questions, Simple Answers Creating a full chart of Zerg builds Relatively freeroll strategies
Other Games
General Games
General RTS Discussion Thread Path of Exile Nintendo Switch Thread Beyond All Reason Stormgate/Frost Giant Megathread
Dota 2
Looking for a Dota Mentor 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
TL Mafia
TL Mafia Power Rank NeO.D_StephenKing vs This Guy From 1 Million Dance TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread The Games Industry And ATVI Russo-Ukrainian War Thread UK Politics Mega-thread YouTube Thread
Fan Clubs
The IdrA Fan Club The HerO Fan Club!
Media & Entertainment
Movie Discussion! Anime Discussion Thread [Req][Books] Good Fantasy/SciFi books Series you have seen recently...
Sports
2024 - 2026 Football Thread MLB/Baseball 2023 McBoner: A hockey love story Tennis[sport] Formula 1 Discussion
World Cup 2022
Tech Support
Simple Questions Simple Answers FPS when play League Of Legend on laptop How to clean a TTe Thermaltake keyboard?
TL Community
Northern Ireland Global Starcraft The Automated Ban List
Blogs
Poker (part 2)
Nebuchad
The Experiences We Want and …
TrAiDoS
An Exploration of th…
waywardstrategy
Gauntlet SC2: A Retrospectiv…
Ctone23
ramps on octagon
StaticNine
Funny Nicknames
LUCKY_NOOB
Evil Gacha Games and the…
ffswowsucks
Customize Sidebar...

Website Feedback

Closed Threads



Active: 7284 users

The Big Programming Thread - Page 415

Forum Index > General Forum
Post a Reply
Prev 1 413 414 415 416 417 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.
sluggaslamoo
Profile Blog Joined November 2009
Australia4494 Posts
Last Edited: 2013-12-28 04:47:40
December 28 2013 04:33 GMT
#8281
On December 28 2013 12:43 berated- wrote:
Show nested quote +
On December 28 2013 05:16 Yoshi- wrote:
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.


Lambdas, yield, map and collect would make it DRY. You wouldn't use the same methods though, you would yield cells from the board using a lambda and then in combination with another lambda which took parameters, you would pass in as a block based on the different permutations to solve it.

Nothing wrong with not adding braces, its the same as adding comments. Don't add them if you don't need them.

If you really find a fault with this because I used Netbeans then you're really just a troll. I use Linux/Xmonad and Vim, but I was rushed for time and thought it would be easier for him if I uploaded a Netbeans project. So I did it in Windows/Netbeans.

Also you guys need to upload your own code before you say anything.
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:08:16
December 28 2013 04:35 GMT
#8282
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;
}


How would you do it?

On November 12 2013 01:52 Yoshi- wrote:
Show nested quote +
On November 11 2013 07:30 sluggaslamoo wrote:

If you have any functions that are longer than 10 lines seriously have a look at them and see if you can't break them down. Most of my functions are 1-3 (ruby) lines long, this is due to functional programming though, I'd say for PHP they should float between 3 to 5 lines on average.


Yea that is bullshit
I all up for splitting code into smaller part, but saying that you should average between 3 to 5 lines is just ridiculous


Would you like some cold water for your burn?

I really just think you don't know much about programming, keep limiting yourself and thinking everything is bullshit. And trolling one of the bigger contributors to this thread while contributing none of your own.

My average was 2.97, adding a brace using the standard method would maybe add 1 or 2 lines to some methods, a lot of them none at all. So 4-5? That still fits within 3-5 lines. Only two methods were longer than 5 lines as well.

By the way not once did I think about lines of code throughout, if you have good basics, that's what you'll get. Actually as I was rushing this, I was barely thinking at all, just sticking to basics. That's the entire point, functional decomposition.

Let me know if you want any programming lessons.

[image loading]
Come play Android Netrunner - http://www.teamliquid.net/forum/viewmessage.php?topic_id=409008
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
December 28 2013 04:53 GMT
#8283
Hi guys, in the midst of your blazing argument I know some of you like game engines, so I posting this here to grab your attention because I'm making one.

/me fade away ...
Cyx.
Profile Joined November 2010
Canada806 Posts
Last Edited: 2013-12-28 06:46:43
December 28 2013 06:33 GMT
#8284
On December 28 2013 04:53 sluggaslamoo wrote:
Show nested quote +
On November 12 2013 01:52 Yoshi- wrote:
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"
On November 12 2013 01:52 Yoshi- wrote:
On November 11 2013 07:30 sluggaslamoo wrote:

If you have any functions that are longer than 10 lines seriously have a look at them and see if you can't break them down. Most of my functions are 1-3 (ruby) lines long, this is due to functional programming though, I'd say for PHP they should float between 3 to 5 lines on average.


Yea that is bullshit
I all up for splitting code into smaller part, but saying that you should average between 3 to 5 lines is just ridiculous


Would you like some cold water for your burn?



zing.

okay for real, I'm pretty over it. Kind of excited for this though...

On December 28 2013 13:53 CecilSunkure wrote:
Hi guys, in the midst of your blazing argument I know some of you like game engines, so I posting this here to grab your attention because I'm making one.

/me fade away ...


I'll totally check it out, as you already know I learned a ton from your asciiengine ^^

e: whoa quotes were all fucked up
mihajovics
Profile Joined April 2011
179 Posts
December 28 2013 10:57 GMT
#8285
On December 28 2013 13:02 Zocat wrote:
Show nested quote +
On December 28 2013 10:46 mihajovics wrote:
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.


thanks, i'm familiar with both, and I use them when I need to do statistical calculations.
for n-grams, I wrote my own python code though...
What I meant was that purely formal language approaches were unsuccessful... grammar parsers are still important and relevant.
InvaderUK
Profile Joined January 2011
225 Posts
Last Edited: 2013-12-28 12:41:58
December 28 2013 11:50 GMT
#8286
On December 28 2013 13:35 sluggaslamoo wrote:
Show nested quote +
On December 28 2013 05:16 Yoshi- wrote:
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;
}


How would you do it?

Show nested quote +
On November 12 2013 01:52 Yoshi- wrote:
On November 11 2013 07:30 sluggaslamoo wrote:

If you have any functions that are longer than 10 lines seriously have a look at them and see if you can't break them down. Most of my functions are 1-3 (ruby) lines long, this is due to functional programming though, I'd say for PHP they should float between 3 to 5 lines on average.


Yea that is bullshit
I all up for splitting code into smaller part, but saying that you should average between 3 to 5 lines is just ridiculous


Would you like some cold water for your burn?

I really just think you don't know much about programming, keep limiting yourself and thinking everything is bullshit. And trolling one of the bigger contributors to this thread while contributing none of your own.

My average was 2.97, adding a brace using the standard method would maybe add 1 or 2 lines to some methods, a lot of them none at all. So 4-5? That still fits within 3-5 lines. Only two methods were longer than 5 lines as well.

By the way not once did I think about lines of code throughout, if you have good basics, that's what you'll get. Actually as I was rushing this, I was barely thinking at all, just sticking to basics. That's the entire point, functional decomposition.

Let me know if you want any programming lessons.

[image loading]


I agree with your sentiment of splitting functionality into short functions that do one thing well, for the most part it is completely possible and good practice. Most (but not all) functions shouldn't be longer than 10 lines.

However there is code reuse in those three functions quoted. Since each function is creating a list, iterating through the tiles, adding cells to the list and returning it.

One could write a function which does the work described, and takes input telling it what parameters it should use with getCell while iterating through the tile space.

The result would be one slightly longer function which does the work of those three functions, and also has functionality that extends beyond them. (If you wanted to get tiles in a different manner, modify the parameters of this function rather than defining another function.)

EDIT:

On further reflection, passing in arguments to replace those functions is probably a bit of a stretch. You can still use a map function which iterates over widthTiles and pass in smaller functions that get the required cell. This would make your four getter functions one liners rather than 4-5 liners (Four lines is clearly too long for any function /s).

I don't write Java so unsure of implementing the mapping function as I've heard it doesn't properly support first class functions.

JS proof of concept:


var getDiagBottom = function(i) {
return getCell(i, widthTiles - i - 1);
};

var getDiagTop = function(i) {
return getCell(i, i);
};

// Returns a function which searches along a specific column.
var getColumn = function(columnNumber) {
return function(i) {
getCell(columnNumber, i);
};
};

// Takes an iterator function to build a list of tiles.
var getTiles = function(fn) {
var tiles = [];
for (var i = 0; i < widthTiles; i++)
tiles.push(fn(i));
return tiles;
};

// getTiles(getColumn(1));
// getTiles(getDiagTop);
// getTiles(getDiagBottom);
patriarch of the church of howard. may maokai smile upon you.
sluggaslamoo
Profile Blog Joined November 2009
Australia4494 Posts
Last Edited: 2013-12-28 15:23:20
December 28 2013 14:28 GMT
#8287
On December 28 2013 20:50 InvaderUK wrote:
Show nested quote +
On December 28 2013 13:35 sluggaslamoo wrote:
On December 28 2013 05:16 Yoshi- wrote:
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;
}


How would you do it?

On November 12 2013 01:52 Yoshi- wrote:
On November 11 2013 07:30 sluggaslamoo wrote:

If you have any functions that are longer than 10 lines seriously have a look at them and see if you can't break them down. Most of my functions are 1-3 (ruby) lines long, this is due to functional programming though, I'd say for PHP they should float between 3 to 5 lines on average.


Yea that is bullshit
I all up for splitting code into smaller part, but saying that you should average between 3 to 5 lines is just ridiculous


Would you like some cold water for your burn?

I really just think you don't know much about programming, keep limiting yourself and thinking everything is bullshit. And trolling one of the bigger contributors to this thread while contributing none of your own.

My average was 2.97, adding a brace using the standard method would maybe add 1 or 2 lines to some methods, a lot of them none at all. So 4-5? That still fits within 3-5 lines. Only two methods were longer than 5 lines as well.

By the way not once did I think about lines of code throughout, if you have good basics, that's what you'll get. Actually as I was rushing this, I was barely thinking at all, just sticking to basics. That's the entire point, functional decomposition.

Let me know if you want any programming lessons.

[image loading]


I agree with your sentiment of splitting functionality into short functions that do one thing well, for the most part it is completely possible and good practice. Most (but not all) functions shouldn't be longer than 10 lines.

However there is code reuse in those three functions quoted. Since each function is creating a list, iterating through the tiles, adding cells to the list and returning it.

One could write a function which does the work described, and takes input telling it what parameters it should use with getCell while iterating through the tile space.

The result would be one slightly longer function which does the work of those three functions, and also has functionality that extends beyond them. (If you wanted to get tiles in a different manner, modify the parameters of this function rather than defining another function.)

EDIT:

On further reflection, passing in arguments to replace those functions is probably a bit of a stretch. You can still use a map function which iterates over widthTiles and pass in smaller functions that get the required cell. This would make your four getter functions one liners rather than 4-5 liners (Four lines is clearly too long for any function /s).

I don't write Java so unsure of implementing the mapping function as I've heard it doesn't properly support first class functions.

JS proof of concept:


var getDiagBottom = function(i) {
return getCell(i, widthTiles - i - 1);
};

var getDiagTop = function(i) {
return getCell(i, i);
};

// Returns a function which searches along a specific column.
var getColumn = function(columnNumber) {
return function(i) {
getCell(columnNumber, i);
};
};

// Takes an iterator function to build a list of tiles.
var getTiles = function(fn) {
var tiles = [];
for (var i = 0; i < widthTiles; i++)
tiles.push(fn(i));
return tiles;
};

// getTiles(getColumn(1));
// getTiles(getDiagTop);
// getTiles(getDiagBottom);


Yup exactly, not just map, but functional programming in general. Javascript is a functional programming language, lambdas, map, etc, are not available in Java, although you could use anonymous functions but it would look ugly as hell.

If I were to use a programming language that supported functional programming though, my code would look completely different from top to bottom, not just for row solving.

If I were to look at that example specifically, I might do it like this in Ruby. Off the top of my head so there might be some weirdness, but you get the general idea.


class Array
def to_row #etc
end

class Row
def solved? #etc
end

def check_results
end_game if [
{ |i| [0..3].map {|col| cells[col, i]} },
{ |i| [0..3].map {|row| cells[i, row]} },
{|i| cells[i, i]},
{|i| cells[i, 3-i-1]}
].select { |proc| [0..3].map{|i| proc(i)}.to_row.solved? }.any?
end
Come play Android Netrunner - http://www.teamliquid.net/forum/viewmessage.php?topic_id=409008
klo8
Profile Joined August 2010
Austria1960 Posts
December 28 2013 15:18 GMT
#8288
So I've been messing around with Clojure a little bit and I think I'm slowly starting to 'get' it. I'd appreciate any feedback on this simple L-System parser/renderer that I've ported over from Scala. The thing is that I know that some things are not as elegant/idiomatic as they could be (especially the step function in core.clj) but I don't know enough yet to make it look nicer. That said, Clojure is really fun to use. I really like the clean syntax.
This post is clearly not a hurr, as you can see from the graph, the durr never intersects with the derp.
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2013-12-28 20:02:22
December 28 2013 19:40 GMT
#8289
How do you guys come up with good variable names? For example, I had to create a method to check if a row or a column is in bounds. However, I didn't know how to properly name the variable, so I just ended up with this name: "int rowOrCol".

Another question, if you type 0 as an array index instead of a constant variable (e.g. MINIMUM_INDEX), is that acceptable or is it still a "magic number"?

Edit:

One more question, is it possible to enumerate an ArrayList in Java by using just generics? I've tried something like:


for (T t : arrayList) {
t.method();
}


It didn't work. As far as I know, it could work in Objective-C if I type something like:


for (id *object in arrayList) {
[object method];
}
Warri
Profile Joined May 2010
Germany3208 Posts
Last Edited: 2013-12-28 21:11:08
December 28 2013 20:19 GMT
#8290
SOLVED the problem, scroll down if youre interested, ignore this post if not

I finally got around to program my..thingy.. which can capture a screenshot from and send fake input to windows that arent in the foreground. I used the JNA library and it works but only kind of. Im gonna skip the capture part, because that works flawlessly, so theres no problem with getting the window etc. It just seems to be ignoring the input.
Relevant code:
 
interface User32 extends com.sun.jna.platform.win32.User32 {
User32 INSTANCE = (User32) Native.loadLibrary(User32.class, W32APIOptions.UNICODE_OPTIONS);
LRESULT SendMessage(HWND hWnd, int Msg, WPARAM wParam, LPARAM lParam);
}
private static final User32 USER = User32.INSTANCE;
public static void main(String[] args) throws IOException, InterruptedException {
WinDef.HWND target = USER.FindWindow(null, "windowname");
USER.PostMessage(target, 0x0201, new WinDef.WPARAM(0x01), new WinDef.LPARAM(16 | 41 << 16));
Thread.sleep(50);
USER.PostMessage(target, 0x0202, new WinDef.WPARAM(0x00), new WinDef.LPARAM(16 | 41 << 16));
}

Now if i try this with "TeamSpeak 3" it will successfully fake the input and push a button, but on another application it just gets ignored. It doesnt matter if i use SendMessage or PostMessage. I used Spy++ to confirm that the input is being sent to the right window and that the window received it. Heres the output:
[image loading]
Now there are a few more messages being sent with a manual input. After a bit of twiddling around i managed to reproduce them too.

WinDef.HWND target = USER.FindWindow(null, "windowname");

USER.SendMessage(target, 0x0084,null, new WinDef.LPARAM(16 | 41 << 16));
USER.SendMessage(target, 0x0020,new WinDef.WPARAM(0x001A067C), new WinDef.LPARAM(1 | 0x0201 << 16));
USER.PostMessage(target, 0x0201, new WinDef.WPARAM(0x01), new WinDef.LPARAM(16 | 41 << 16));
Thread.sleep(50);

USER.SendMessage(target, 0x0084,null, new WinDef.LPARAM(16 | 41 << 16));
USER.SendMessage(target, 0x0020,new WinDef.WPARAM(0x001A067C), new WinDef.LPARAM(1 | 0x0202 << 16));
USER.PostMessage(target, 0x0202, new WinDef.WPARAM(0x00), new WinDef.LPARAM(16 | 41 << 16));

[image loading]
But it still doesnt work. What am i doing wrong?
PostMessage SHOULD work, because its what hotkeynet uses and it works there.
http://hotkeynet.com/ref/sendwinm.html
SendWinM is used with background windows. It calls the operating system command PostMesssage which does not wait after each character for a response from the receiving thread. This makes SendWinM fast but possibly less reliable than SendWinS.

Edit: for comparison, this is what it looks like if i use hotkeynet, to broadcast mouseclicks i do in a different window to eve while its not in the foreground:
[image loading]

Edit: SOLVED By checking the hotkeynet output above i noticed that it sends a mousemove message first, which isnt necessary for a manual click. But if i want to fake it i have to move the mouse in position first, just click(postion) didnt work. So by adding
USER.SendMessage(target,0x0200,null,new WinDef.LPARAM(16|41<<16));

i managed to make it work!
sluggaslamoo
Profile Blog Joined November 2009
Australia4494 Posts
Last Edited: 2013-12-29 05:34:09
December 29 2013 05:31 GMT
#8291
On December 29 2013 04:40 darkness wrote:
How do you guys come up with good variable names? For example, I had to create a method to check if a row or a column is in bounds. However, I didn't know how to properly name the variable, so I just ended up with this name: "int rowOrCol".

Another question, if you type 0 as an array index instead of a constant variable (e.g. MINIMUM_INDEX), is that acceptable or is it still a "magic number"?

Edit:

One more question, is it possible to enumerate an ArrayList in Java by using just generics? I've tried something like:


for (T t : arrayList) {
t.method();
}


It didn't work. As far as I know, it could work in Objective-C if I type something like:


for (id *object in arrayList) {
[object method];
}


Yes its possible, maybe you aren't typecasting correctly? There's a few examples in the java code I posted on github before.

Nothing wrong with magic numbers if it is obvious to the programmer, such as 0. However the reason you want to avoid them is flexibility, if you want variable board sizing for example, your program won't work with magic numbers.

The method should return the condition of whether the object is in bounds, there's no need for a variable I don't think, if that makes any sense.

e.g

return index < rbound && index > lbound

Depends how complicated it is, or you could create a class which is a generalisation of row and column, and that can have a bounds method. Or if you mean the actual row or column has to be in bounds, then pass the generalisation into the container.

cellArray.inBounds(index)

or

container.inBounds(cellArray)
Come play Android Netrunner - http://www.teamliquid.net/forum/viewmessage.php?topic_id=409008
klo8
Profile Joined August 2010
Austria1960 Posts
December 29 2013 11:23 GMT
#8292
On December 29 2013 04:40 darkness wrote:
How do you guys come up with good variable names? For example, I had to create a method to check if a rthere are only two hard things in computer science cache invalidation and naming thingsow or a column is in bounds. However, I didn't know how to properly name the variable, so I just ended up with this name: "int rowOrCol".

Another question, if you type 0 as an array index instead of a constant variable (e.g. MINIMUM_INDEX), is that acceptable or is it still a "magic number"?

Edit:
One more question, is it possible to enumerate an ArrayList in Java by using just generics? I've tried something like:


for (T t : arrayList) {
t.method();
}


It didn't work. As far as I know, it could work in Objective-C if I type something like:


for (id *object in arrayList) {
[object method];
}

"There are two hard things in computer science: cache invalidation, naming things, and off-by-one errors."

So, naming things is hard. Also, putting some named constant instead of 0 if you just want to access the first element of an array would just be confusing (something like MIN_IDX or whatever would imply to me that it's not 0).

If you want to loop over an array like you described, you do have to have the type variable T declared somewhere (either in a class or in a method). I just tried this and it worked as expected:

import java.util.ArrayList;

public class ArrayListTest {
public static <T> void iterate(ArrayList<T> list) {
for(T t: list) {
System.out.println(t.toString());
}
}

public static void main(String[] args) {
ArrayList<Integer> list = new ArrayList<>();
list.add(2);
list.add(3);
iterate(list);
}
}

Output:
2
3
This post is clearly not a hurr, as you can see from the graph, the durr never intersects with the derp.
phar
Profile Joined August 2011
United States1080 Posts
December 29 2013 20:24 GMT
#8293
On December 29 2013 20:23 klo8 wrote:
"There are two hard things in computer science: cache invalidation, naming things, and off-by-one errors."

The two top sources of bugs in programming are concur buffer overfl*&^(%, rency, and off-by-one errors.

(not original, I'm not nearly that clever :p)
Who after all is today speaking about the destruction of the Armenians?
wozzot
Profile Joined July 2012
United States1227 Posts
Last Edited: 2013-12-29 22:06:16
December 29 2013 20:30 GMT
#8294
Programming newbie, making a Rubik's Cube solver, feeling really dumb right now.

I think I can manage to get the cube structure, the transformation subroutine, and solver algorithm going, but I don't know how the hell I should store the cubelet data, the data that tells me that the TL corner of the top face is connected to the TL of the left face and TR of the back face so that I can rotate them together and so on.

Right now, I'm using this and using split to retrieve the face + side/corner pairs:


my cubelets[6][9];
{
cubelets[0][0] = ( ["1 0", "4 2"] );
cubelets[0][1] = "4 1";
cubelets[0][2] = ( ["4 0", "3 2"] );
cubelets[0][3] = "1 1";
cubelets[0][5] = "3 1";
cubelets[0][6] = ( ["1 2", "2 0"] );
cubelets[0][7] = "2 1";
cubelets[0][8] = ( ["2 2", "3 0"] );

cubelets[1][0] = ( ["0 0", "4 2"] );
cubelets[1][1] = "0 3";
cubelets[1][2] = ( ["0 6", "2 0"] );
cubelets[1][3] = "4 5";
cubelets[1][5] = "2 3";
cubelets[1][6] = ( ["4 8", "5 6"] );
cubelets[1][7] = "5 3";
cubelets[1][8] = ( ["2 6", "5 0"] );

cubelets[2][0] = ( ["0 6", "1 2"] );
cubelets[2][1] = "0 7";
cubelets[2][2] = ( ["0 8", "3 0"] );
cubelets[2][3] = "1 5";
cubelets[2][5] = "3 3";
cubelets[2][6] = ( ["1 8", "5 0"] );
cubelets[2][7] = "5 1";
cubelets[2][8] = ( ["3 6", "5 2"] );

...

But I'm pretty sure that this is either non-optimal or I might be approaching this problem completely the wrong way. Am I doing something wrong? Any advice on how to go about doing this?

e: Only on Layer 1 and it's already about 250 lines of code, I'm definitely screwing something up but may as well keep on going
(ノ´∀`*)ノ ♪ ♫ ヽ(´ー`)ノ ♪ ♫ (✌゚∀゚)☞ ♪ ♫ ヽ(´ー`)ノ ♫ ♫ (ノ´_ゝ`)ノ彡 ┻━┻
Liebig
Profile Joined August 2010
France738 Posts
December 29 2013 20:47 GMT
#8295
Wouldn't using a 3*3*3 array containing the color of the faces do it ?
_IPX
Profile Joined November 2013
3 Posts
December 29 2013 21:01 GMT
#8296
I have no idea why I can't find the answer anywhere, but how do you execute scripts in Python? I've used notepad to save
lines of code in a .py file and then try calling it in the interpreter with "python myfile.py" and "$ python myfile.py" with no success. Stuck for hours, asking here as a last resort.
I wish that people who are conventionally supposed to love each other would say to each other, when they fight, "Please - a little less love, and a little more common decency
teamamerica
Profile Blog Joined July 2010
United States958 Posts
December 29 2013 21:12 GMT
#8297
Anyone have advice on good books/pointers on designing stuff? Writing in object orientated languages, one thing I struggle with is how to design my classes. Things like: should this be static function or instance. Should this be in constructor or passed into function. Should I pass an object and act on a copy, or mutate the object that was passed in.

Also the same question about good references for how to set up relational database schema? e.g. surrogate keys vs natural keys.

One thing I was just working on was...
+ Show Spoiler +

One thing I just worked on had records which had either a "rast" or "patric" type annotation. Each annotation type provided different information i.e. different columns. So for each record I stored "annotation type" as an "enum", and had 2 tables {rast, patric} annotation. My question in this case is twofold:
1) better to have split it into 2 tables or used one larger table (annotation) and nulled out columns as appropriate
2) better to use enum to describe annotation type or a values table (e.g. annotation type column => annotation_types table => "rast" | "patric".
3) and this might be mysql specific. Some of the columns in the annotation table are rather large - 500char+. When to use varchar(500) or "TEXT". Say the column "length" is 500+ characters. I've seen before comments that TEXT and BLOB columns can make table operations that don't even effect these columns really expensive. Should I have stored "length" in a seperate table, and had a lookup table from the main record to it?

The data seemed pretty relational but it feels weird to columns with so much text into a database.


I'm looking through Effective Java which I find pretty interesting, and it kind of covers questions of the second instance, but not really questions of the first instance.
RIP GOMTV. RIP PROLEAGUE.
teamamerica
Profile Blog Joined July 2010
United States958 Posts
Last Edited: 2013-12-29 21:17:56
December 29 2013 21:17 GMT
#8298
On December 30 2013 06:01 _IPX wrote:
I have no idea why I can't find the answer anywhere, but how do you execute scripts in Python? I've used notepad to save
lines of code in a .py file and then try calling it in the interpreter with "python myfile.py" and "$ python myfile.py" with no success. Stuck for hours, asking here as a last resort.


If ">python myfile.py" doesn't work, is the "python.exe" in your PATH? I'm assuming you're on windows that is.
RIP GOMTV. RIP PROLEAGUE.
Nyxisto
Profile Joined August 2010
Germany6287 Posts
Last Edited: 2013-12-29 21:44:01
December 29 2013 21:43 GMT
#8299
http://research.microsoft.com/en-us/people/mickens/thenightwatch.pdf

I don't know if that has been posted before, but it's hilarious.
Cyx.
Profile Joined November 2010
Canada806 Posts
December 29 2013 22:05 GMT
#8300
On December 30 2013 06:01 _IPX wrote:
I have no idea why I can't find the answer anywhere, but how do you execute scripts in Python? I've used notepad to save
lines of code in a .py file and then try calling it in the interpreter with "python myfile.py" and "$ python myfile.py" with no success. Stuck for hours, asking here as a last resort.

You don't want to call it in the interpreter - you want to use that same command from the command line ^^
Prev 1 413 414 415 416 417 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 4h 12m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
mouzHeroMarine 584
UpATreeSC 321
ZombieGrub81
BRAT_OK 66
CosmosSc2 53
JuggernautJason32
MindelVK 12
StarCraft: Brood War
HiyA 70
NaDa 14
ajuk12(nOOB) 7
Dota 2
qojqva3445
Counter-Strike
ScreaM1343
fl0m1250
Super Smash Bros
hungrybox258
Heroes of the Storm
Liquid`Hasu350
Other Games
tarik_tv4814
Grubby2338
Beastyqt740
shahzam679
B2W.Neo380
XaKoH 220
mouzStarbuck136
ToD116
Livibee84
Trikslyr62
SteadfastSC32
Organizations
Other Games
gamesdonequick2068
StarCraft 2
TaKeTV642
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 18 non-featured ]
StarCraft 2
• StrangeGG 93
• LaughNgamezSOOP
• AfreecaTV YouTube
• sooper7s
• intothetv
• Migwel
• Kozan
• IndyKCrew
StarCraft: Brood War
• blackmanpl 26
• 80smullet 25
• HerbMon 22
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• masondota2110
League of Legends
• TFBlade1087
Other Games
• imaqtpie979
• Shiphtur359
Upcoming Events
Replay Cast
4h 12m
RSL Revival
13h 12m
Clem vs Lambo
Scarlett vs Cure
CranKy Ducklings
14h 12m
Epic.LAN
17h 12m
IPSL
20h 12m
Dragon vs Hawk
RSL Revival
1d 13h
Classic vs Trap
herO vs SHIN
Sparkling Tuna Cup
1d 14h
OSC
1d 17h
IPSL
1d 20h
Bonyth vs Ret
WardiTV Weekly
2 days
[ Show More ]
Monday Night Weeklies
2 days
PiGosaur Cup
4 days
The PondCast
4 days
Replay Cast
5 days
CrankTV Team League
5 days
Replay Cast
6 days
CrankTV Team League
6 days
Liquipedia Results

Completed

Proleague 2026-07-13
HSC XXIX
Eternal Conflict S2 E2

Ongoing

IPSL Spring 2026
Acropolis #4
YSL S3
CSL 2026 Summer (S21)
KCM Race Survival 2026 Season 3
Escore Tournament S3: W3
RSL Revival: Season 6
CranK Gathers Season 4: BW vs SC2 Team League
SCTL 2026 Spring
Stake Ranked Episode 3
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026

Upcoming

ASL S22 SEASON OPEN Day 1
Escore Tournament S3: W4
ASL S22 SEASON OPEN Day 2
Escore Tournament S3: W5
CSLAN 4
Blizzard Classic Cup 2026
HSC XXX
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
Light Tournament 2026
Eternal Conflict S2 Finale
Eternal Conflict S2 E3
Logitech G Connect 2026
StarSeries Fall 2026
FISSURE Playground #5
BLAST Open Fall 2026
Esports World Cup 2026
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
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.