• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 04:27
CET 10:27
KST 18:27
  • 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
Chinese SC2 server to reopen; live all-star event in Hangzhou 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
Tourneys
RSL Offline Finals Info - Dec 13 and 14! StarCraft Evolution League (SC Evo Biweekly) RSL Offline FInals Sea Duckling Open (Global, Bronze-Diamond) $5,000+ WardiTV 2025 Championship
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
BW General Discussion Which season is the best in ASL? Data analysis on 70 million replays BGH Auto Balance -> http://bghmmr.eu/ [ASL20] Ask the mapmakers — Drop your questions
Tourneys
[BSL21] RO16 Group D - Sunday 21:00 CET [BSL21] RO16 Group A - Saturday 21:00 CET [Megathread] Daily Proleagues [BSL21] RO16 Group B - Sunday 21:00 CET
Strategy
Current Meta Game Theory for Starcraft How to stay on top of macro? PvZ map balance
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread ZeroSpace Megathread The Perfect Game Path of Exile
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 US Politics Mega-thread Things Aren’t Peaceful in Palestine 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
Physical Exertion During Gam…
TrAiDoS
James Bond movies ranking - pa…
Topin
Thanks for the RSL
Hildegard
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1657 users

The Big Programming Thread - Page 538

Forum Index > General Forum
Post a Reply
Prev 1 536 537 538 539 540 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.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
October 27 2014 17:52 GMT
#10741
What is your stance towards using function names/creating new functions to document the function (when you're creating a new method not necessarily used in other places but makes the intent of the code clearer)


def main():
file = getInputFromFile()
n = getCharFromFile(file)

for i to n:
c = getCharFromFile(file)

for j to c:
x[i] = getCharFromFile(file)

doStuff(x)


versus


def doCase(c):
for i to c:
x[i] = getCharFromFile(file)
doStuff(x)

def readCases():
n = getCharFromFile(file)
for i to n:
c = getCharFromFile(file)
doCase(c)

def main():
file = getInputFromFile()
readCases()


Obviously more code but basically that idea. If a group of methods/functions with somewhat complex control flow could be simplified down to a single action, would you prefer wrapping that in a function or prefacing the control flow with a comment.
There is no one like you in the universe.
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
Last Edited: 2014-10-27 18:09:24
October 27 2014 18:02 GMT
#10742
My opinion on that is: whenever you feel the need to put a comment inside a method, you should extract that code into a new method with "the comment as it's name" (you know what I mean).

Sometimes it doesn't work so nicely because the new method would need too many parameters. In that case there's usually still hope that there is a different, better approach to the whole algorithm, which in turn allows for better method extractions.

I really don't care too much about reuse of my methods. I do avoid duplication, of course. If one of my small methods happens to be reusable, great. I also frequently apply a series of inline and extract method refactorings whenever I see some duplicate behavior but my methods aren't quite ready for the situation yet.
If you have a good reason to disagree with the above, please tell me. Thank you.
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
Last Edited: 2014-10-27 18:18:00
October 27 2014 18:14 GMT
#10743
On October 28 2014 02:52 Blisse wrote:
What is your stance towards using function names/creating new functions to document the function (when you're creating a new method not necessarily used in other places but makes the intent of the code clearer)


def main():
file = getInputFromFile()
n = getCharFromFile(file)

for i to n:
c = getCharFromFile(file)

for j to c:
x[i] = getCharFromFile(file)

doStuff(x)


versus


def doCase(c):
for i to c:
x[i] = getCharFromFile(file)
doStuff(x)

def readCases():
n = getCharFromFile(file)
for i to n:
c = getCharFromFile(file)
doCase(c)

def main():
file = getInputFromFile()
readCases()


Obviously more code but basically that idea. If a group of methods/functions with somewhat complex control flow could be simplified down to a single action, would you prefer wrapping that in a function or prefacing the control flow with a comment.


I know that our compiler will inline most functions if it's called under an arbitrary 5 times. So this sort of abstraction has little actual actual effect on code-size. Personal preference then, I guess. There are valid arguments for both styles.

The only correct argument is to be consistent with the practices of nearby code.

On October 28 2014 03:02 spinesheath wrote:
My opinion on that is: whenever you feel the need to put a comment inside a method, you should extract that code into a new method with "the comment as it's name" (you know what I mean).

Sometimes it doesn't work so nicely because the new method would need too many parameters. In that case there's usually still hope that there is a different, better approach to the whole algorithm, which in turn allows for better method extractions.

I really don't care too much about reuse of my methods. I do avoid duplication, of course. If one of my small methods happens to be reusable, great. I also frequently apply a series of inline and extract method refactorings whenever I see some duplicate behavior but my methods aren't quite ready for the situation yet.


+1 for the "comment as it's name".

My personal favorite coding standard is from https://github.com/contiki-os/contiki/blob/master/doc/code-style.c

functions or variables are prepended with the name of the file it comes from, as well, so you can navigate the code-base without a heavy IDE fairly easily.

Any sufficiently advanced technology is indistinguishable from magic
StatixEx
Profile Blog Joined August 2011
United Kingdom779 Posts
Last Edited: 2014-10-27 19:31:05
October 27 2014 19:28 GMT
#10744
thank you for the advice to a question i posted in page 537.

What im looking for is something graphical and impressive with VERY straight forward to understand code. Ive been programming for the best part of 15 years now and know how long i spent practicing code and exploring and having some of the most accomplished feelings in my life from it. Ive decided to settle down a bit and took a teaching job from games design and stuff like that and feel extremely frustrated with the 11-16yr olds of today. I teach computing of course, our schools most advanced accomplishment is a nested if in excel . . . or a vlookup(rest of staff think they are genius programmers as well when they actually put it up in board and know what the arguments are . . i digress)and even then ive never seen anyone write it out without there being mistakes which ive had to fix in the end anyway.

so ,what am i saying and asking

I tried for years to use flash with them, AS2 was good! AS3 took it all away making it harder to just write scripts into actual objects, now they have to know how to program to an extent and use calls from imports to make anything work the way it did! I personally think its what AS was waiting for, but for the kid . . . nope!

i saw a comp on some site called program a game in a day and some dude made a really good gauntlet/zelda like game using python. I saw the code and thought this isnt so much! kids might get this!

I copied the code, took out everything i didn't need . . infact all i had was a guy running around on some grass and there was a chest you could open. but the [ for x, for y loop into the if x in y ] to draw the tiles threw the kids instantly. they couldnt get their head round a 2d array kind of setup and how the tiles were being drawn to the screen, then came the main entry loop which . . . .well it was over when we got to this bit. Most of the kids had a hard time copying the functions at the start properly.

So, again what am i asking . . not sure but no matter what i try to do, construct of programs seem to get heavy too fast . . .well i say this but i find it insanely straight forward and easy . . .the kids dont get it. All i can do in my lesson in teach them trivial examples, explain whats happening and there we go . . . looks like they are getting it. They cant seem to put this knowledge and practice outside a simple, get a program to output your name, enter a number and display that as your age kind of shit!

Im going to try a class based approach next week and develop something really dumb like a dishwasher . . . god teaching man, kids DONT want to go away and do any extra work or research, if they arent playing COD made by them in 12 minutes its over


spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
Last Edited: 2014-10-27 20:10:32
October 27 2014 20:09 GMT
#10745
"11-16 year olds today" is something countless generations before you have complained about.

Not everyone is talented at or even interested in programming and while I think that most people can learn to program at a moderate level given enough time, I doubt you'll have enough of that. Shouldn't your goal be to teach your students the very basics and then support those who are interested and determined enough to learn more than what can be taught at school?

Just like performance optimization: don't waste development time on random parts of the code. Keep everything reasonable, then profile and focus on the parts that have the most potential for optimization.
If you have a good reason to disagree with the above, please tell me. Thank you.
LaNague
Profile Blog Joined April 2010
Germany9118 Posts
October 27 2014 21:06 GMT
#10746
whats your class, what type of school and is the class mandatory or do they sign up for it?
Important things to know.

mandatory basic excel class in a low education school is different than a course where people can opt out of in a high education school.




In my school we did a program for live predictions for city elections amongst other things, i think a later course did their own browsergame.
But those were optional courses only for people who wanted to learn more about programming, 80% of my school would have been helpless in there, just as i would have been helpless in a painting art class.

Manit0u
Profile Blog Joined August 2004
Poland17496 Posts
Last Edited: 2014-10-27 21:12:53
October 27 2014 21:11 GMT
#10747
Has anyone here ever used the pimcore CMS? I've started working for a new company at the end of last week, got assigned some issues pertaining their project using pimcore, which was set up and solely governed by their former employee. No one knows exactly how it works and I've spent past 2 workdays figuring it all out.

Today I've closed 2 issues, which weren't real issues (client got confused) but found some other things that were disturbing:
1. The code that's on the production server doesn't figure on any of the git branches, it's way ahead of master and all the others and there's no way to push it from the production server...
2. While investigating the code and doing some quick fixes for some real issues (had to do it via vim and ssh console) I've discovered that debug.log file has grown to over 200MB over the course of past 2 weeks, most of which were SQL-based errors (majority of them seemed to be state 2002 - unable to open connection to socket), obviously the file was too large for me to parse thoroughly. Investigating php.log revealed some fatal errors involving PDO exceptions... The debug.log is now growing approximately 1MB/hour since people are beginning to fill in content and test it and I have no idea how to handle it in this unfamiliar environment.

Any ideas where to start fixing this? I'm currently looking for a way to disable debug log entirely as the temporary measure, until I figure out what the next course of action should be.
Time is precious. Waste it wisely.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
October 27 2014 21:33 GMT
#10748
--- Nuked ---
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
Last Edited: 2014-10-27 22:38:16
October 27 2014 21:35 GMT
#10749
On October 28 2014 06:11 Manit0u wrote:
Has anyone here ever used the pimcore CMS? I've started working for a new company at the end of last week, got assigned some issues pertaining their project using pimcore, which was set up and solely governed by their former employee. No one knows exactly how it works and I've spent past 2 workdays figuring it all out.

Today I've closed 2 issues, which weren't real issues (client got confused) but found some other things that were disturbing:
1. The code that's on the production server doesn't figure on any of the git branches, it's way ahead of master and all the others and there's no way to push it from the production server...
2. While investigating the code and doing some quick fixes for some real issues (had to do it via vim and ssh console) I've discovered that debug.log file has grown to over 200MB over the course of past 2 weeks, most of which were SQL-based errors (majority of them seemed to be state 2002 - unable to open connection to socket), obviously the file was too large for me to parse thoroughly. Investigating php.log revealed some fatal errors involving PDO exceptions... The debug.log is now growing approximately 1MB/hour since people are beginning to fill in content and test it and I have no idea how to handle it in this unfamiliar environment.

Any ideas where to start fixing this? I'm currently looking for a way to disable debug log entirely as the temporary measure, until I figure out what the next course of action should be.


put up a cron job to compress the log (it should compress very nicely) and archive it for later viewing.

Save the most recent few logs from the last week or so into a folder, and remove older logs if the overall folder gets too big. Every week or so, save a log as an archived log to make sure you have snapshots from common errors around that time from production.


Just some ideas. If you don't think the log will be useful at all, you can just remove the file and pipe it straight to /dev/null by putting a link there.


EDIT: And if you're asking how to actually deal with the errors that come up, start with the most egregious sounding error and slowly but surely work your way until the debug log actually has meaning.

EDIT #2: It is probably worth mentioning that the server generating the logs should probably get a good profiling to make sure all that logging isn't slowing down it's response.
Any sufficiently advanced technology is indistinguishable from magic
Shenghi
Profile Joined August 2010
167 Posts
October 27 2014 21:57 GMT
#10750
On October 28 2014 02:52 Blisse wrote:
What is your stance towards using function names/creating new functions to document the function (when you're creating a new method not necessarily used in other places but makes the intent of the code clearer)


def main():
file = getInputFromFile()
n = getCharFromFile(file)

for i to n:
c = getCharFromFile(file)

for j to c:
x[i] = getCharFromFile(file)

doStuff(x)


versus


def doCase(c):
for i to c:
x[i] = getCharFromFile(file)
doStuff(x)

def readCases():
n = getCharFromFile(file)
for i to n:
c = getCharFromFile(file)
doCase(c)

def main():
file = getInputFromFile()
readCases()


Obviously more code but basically that idea. If a group of methods/functions with somewhat complex control flow could be simplified down to a single action, would you prefer wrapping that in a function or prefacing the control flow with a comment.

In the second case, the functions should be ordered so they can be read from top to bottom; the first one to be called at the top, and then whichever comes next. In this case: main, followed by readCases, followed by doCase.
People are not born stupid, they choose to be stupid. If you made that choice, please change your mind.
Days
Profile Joined February 2010
United States219 Posts
October 28 2014 00:16 GMT
#10751
My fellow nerds! I need your help. I have a C# application due soon and I am stumped. Basically I have to make a simplified version of Paint. What i'm doing for now is drawing Ellipses, Rectangles, and Triangles based on mouse movement. It works pretty nicely, except that when one shape is drawn, the one before that disappears. I know i'm suppose to be using some type of ArrayList to store shapes, but since I have 3 different shapes I am confused as to how to go about that. Here is my code where I add rectangles to the array. (The rectangle is working, but the ellipse and triangles are not being stored)

P.S. Just to not confuse you guys, any code inside the Using(graphics) in my MouseDown event is just to check if a right click falls inside of a created shape. This is in order to open a Properties Dialog that is suppose to be able to change the rotation, location, text, size,width of each drawn shape. I have yet to pass the values, that will be my next monster to tackle.


private void mainFrm_MouseDown(object sender, MouseEventArgs e)
{

initialY = e.Y;
initialX = e.X;
isMoving = true;
using (Graphics g = this.CreateGraphics())
{
if (e.Button == MouseButtons.Right)
{
Point[] ptClick = new Point[] { new Point(e.X, e.Y) };
g.TransformPoints(CoordinateSpace.Page, CoordinateSpace.Device, ptClick);
foreach (Rectangle rect in rectangles)
{
if (rect.Contains(ptClick[0]))
{
options.Show();
}
}
}
}
//this.Invalidate();
}

private void mainFrm_MouseUp(object sender, MouseEventArgs e)
{
isMoving = false;
count++;
//rectangle = new Rectangle(movedX, movedY, width, height);
if (rectangleToolStripMenuItem.Checked == true)
{
rectangles.Add(new Rectangle(movedX, movedY, width, height));
//rectangle = new Rectangle(movedX, movedY, width, height);
}
else if (ellipseToolStripMenuItem.Checked == true)
{
ellipses.Add(new Rectangle(movedX, movedY, width, height));

}
this.Invalidate();
}

private void mainFrm_MouseMove(object sender, MouseEventArgs e)
{
if (isMoving == true)
{
//movedX = e.X - initialX;
//movedY = e.Y - initialY;
triangleX = e.X;
triangleY = e.Y;
movedY = Math.Min(initialY, e.Y);
movedX = Math.Min(initialX, e.X);
width = Math.Max(initialX, e.X) - Math.Min(initialX, e.X);
height = Math.Max(initialY, e.Y) - Math.Min(initialY, e.Y);
rectangles.Insert(0, new Rectangle(movedX, movedY, width, height));

}
this.Invalidate();
}
We buy things we don't need, with money we don't have, to impress people we don't like.
delHospital
Profile Blog Joined December 2010
Poland261 Posts
Last Edited: 2014-10-28 00:42:21
October 28 2014 00:17 GMT
#10752
On October 28 2014 02:52 Blisse wrote:
What is your stance towards using function names/creating new functions to document the function (when you're creating a new method not necessarily used in other places but makes the intent of the code clearer)

+ Show Spoiler +


def main():
file = getInputFromFile()
n = getCharFromFile(file)

for i to n:
c = getCharFromFile(file)

for j to c:
x[i] = getCharFromFile(file)

doStuff(x)


versus


def doCase(c):
for i to c:
x[i] = getCharFromFile(file)
doStuff(x)

def readCases():
n = getCharFromFile(file)
for i to n:
c = getCharFromFile(file)
doCase(c)

def main():
file = getInputFromFile()
readCases()



Obviously more code but basically that idea. If a group of methods/functions with somewhat complex control flow could be simplified down to a single action, would you prefer wrapping that in a function or prefacing the control flow with a comment.
My advice would be this:

When you split up a function, do it bottom up, not top down. That is, don't cut the function in half, and
def big_f():
f1()
f2()
That doesn't really achieve anything. Instead, try to find small small chunks of functionality that can be meaningful on their own, and extract them from the big function. Those will usually take arguments, process them, and return the result, possibly doing a little bit of IO along the way. If you went with the "cut in half" approach, you would have arrived at two weird looking procedures that take nothing, and return nothing.

To elaborate a bit more:

If you refactor
# does this and that
def main():
...
into
# does this
def this():
...

# (possibly hundreds of lines below, or in a different file)
# does that
def that():
...

def main():
this()
that()

Then it becomes easier to see what main() is about, but it comes with a price: that() becomes harder to reason about, as it depends on the state set up by this().

If you instead refactor it like this:
def f(a, b):
# (play with a and b to get a result)
return result

def g(a, b):
...
return result

def main():
# (code that uses f() and g())

Then, as long as f() and g() are sensible, everything becomes smaller and easier to grasp.
Manit0u
Profile Blog Joined August 2004
Poland17496 Posts
Last Edited: 2014-10-28 08:47:09
October 28 2014 08:46 GMT
#10753
On October 28 2014 09:17 delHospital wrote:
Show nested quote +
On October 28 2014 02:52 Blisse wrote:
What is your stance towards using function names/creating new functions to document the function (when you're creating a new method not necessarily used in other places but makes the intent of the code clearer)

+ Show Spoiler +


def main():
file = getInputFromFile()
n = getCharFromFile(file)

for i to n:
c = getCharFromFile(file)

for j to c:
x[i] = getCharFromFile(file)

doStuff(x)


versus


def doCase(c):
for i to c:
x[i] = getCharFromFile(file)
doStuff(x)

def readCases():
n = getCharFromFile(file)
for i to n:
c = getCharFromFile(file)
doCase(c)

def main():
file = getInputFromFile()
readCases()



Obviously more code but basically that idea. If a group of methods/functions with somewhat complex control flow could be simplified down to a single action, would you prefer wrapping that in a function or prefacing the control flow with a comment.
My advice would be this:

When you split up a function, do it bottom up, not top down. That is, don't cut the function in half, and
def big_f():
f1()
f2()
That doesn't really achieve anything. Instead, try to find small small chunks of functionality that can be meaningful on their own, and extract them from the big function. Those will usually take arguments, process them, and return the result, possibly doing a little bit of IO along the way. If you went with the "cut in half" approach, you would have arrived at two weird looking procedures that take nothing, and return nothing.

To elaborate a bit more:

If you refactor
# does this and that
def main():
...
into
# does this
def this():
...

# (possibly hundreds of lines below, or in a different file)
# does that
def that():
...

def main():
this()
that()

Then it becomes easier to see what main() is about, but it comes with a price: that() becomes harder to reason about, as it depends on the state set up by this().

If you instead refactor it like this:
def f(a, b):
# (play with a and b to get a result)
return result

def g(a, b):
...
return result

def main():
# (code that uses f() and g())

Then, as long as f() and g() are sensible, everything becomes smaller and easier to grasp.


I think that's bad. It's way more convenient to have your main function definition at the top and all the helper function definitions below that. The reason is, while inspecting the file you instantly get to the gist of it and if functions have good names you can instantly tell what it does and only have to look up the helper functions if you really need the specifics. Reading random chunks of code doesn't help you understand what the program is actually doing and what its end goal is, you only get that from reading the main function definition. That's why I think it should be the topmost thing.

TL;DR - abstract --> specific is the way to go, not the other way around.
Time is precious. Waste it wisely.
delHospital
Profile Blog Joined December 2010
Poland261 Posts
Last Edited: 2014-10-28 09:28:06
October 28 2014 09:27 GMT
#10754
On October 28 2014 17:46 Manit0u wrote:
Show nested quote +
On October 28 2014 09:17 delHospital wrote:
On October 28 2014 02:52 Blisse wrote:
What is your stance towards using function names/creating new functions to document the function (when you're creating a new method not necessarily used in other places but makes the intent of the code clearer)

+ Show Spoiler +


def main():
file = getInputFromFile()
n = getCharFromFile(file)

for i to n:
c = getCharFromFile(file)

for j to c:
x[i] = getCharFromFile(file)

doStuff(x)


versus


def doCase(c):
for i to c:
x[i] = getCharFromFile(file)
doStuff(x)

def readCases():
n = getCharFromFile(file)
for i to n:
c = getCharFromFile(file)
doCase(c)

def main():
file = getInputFromFile()
readCases()



Obviously more code but basically that idea. If a group of methods/functions with somewhat complex control flow could be simplified down to a single action, would you prefer wrapping that in a function or prefacing the control flow with a comment.
My advice would be this:

When you split up a function, do it bottom up, not top down. That is, don't cut the function in half, and
def big_f():
f1()
f2()
That doesn't really achieve anything. Instead, try to find small small chunks of functionality that can be meaningful on their own, and extract them from the big function. Those will usually take arguments, process them, and return the result, possibly doing a little bit of IO along the way. If you went with the "cut in half" approach, you would have arrived at two weird looking procedures that take nothing, and return nothing.

To elaborate a bit more:

If you refactor
# does this and that
def main():
...
into
# does this
def this():
...

# (possibly hundreds of lines below, or in a different file)
# does that
def that():
...

def main():
this()
that()

Then it becomes easier to see what main() is about, but it comes with a price: that() becomes harder to reason about, as it depends on the state set up by this().

If you instead refactor it like this:
def f(a, b):
# (play with a and b to get a result)
return result

def g(a, b):
...
return result

def main():
# (code that uses f() and g())

Then, as long as f() and g() are sensible, everything becomes smaller and easier to grasp.


I think that's bad. It's way more convenient to have your main function definition at the top and all the helper function definitions below that. The reason is, while inspecting the file you instantly get to the gist of it and if functions have good names you can instantly tell what it does and only have to look up the helper functions if you really need the specifics. Reading random chunks of code doesn't help you understand what the program is actually doing and what its end goal is, you only get that from reading the main function definition. That's why I think it should be the topmost thing.

TL;DR - abstract --> specific is the way to go, not the other way around.

I'm not talking about how functions should be grouped into modules or about the ordering of function definitions in a file. Yes, putting the helper functions below is probably a good idea, but that's not what my post was about. I was saying that you should primarily extract pure-ish, reusable-ish functions that can be reasoned about in isolation, and that simply dividing a procedure into several smaller ones gains you much less.
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
October 28 2014 09:37 GMT
#10755
When I want to cut a method into parts, I try to describe what the method does in 2-4 steps and then make those steps my methods. That way I can read the original method as a series of 2-4 steps and then look deeper if I need details about one step. Good steps are usually just those that have a good name and don't require super specific input parameters (so they can work in isolation).

I do think we all mean the same thing here, by the way.
If you have a good reason to disagree with the above, please tell me. Thank you.
Poirier255
Profile Joined July 2013
Canada2 Posts
October 28 2014 20:23 GMT
#10756
On October 28 2014 09:16 Days wrote:
+ Show Spoiler +
My fellow nerds! I need your help. I have a C# application due soon and I am stumped. Basically I have to make a simplified version of Paint. What i'm doing for now is drawing Ellipses, Rectangles, and Triangles based on mouse movement. It works pretty nicely, except that when one shape is drawn, the one before that disappears. I know i'm suppose to be using some type of ArrayList to store shapes, but since I have 3 different shapes I am confused as to how to go about that. Here is my code where I add rectangles to the array. (The rectangle is working, but the ellipse and triangles are not being stored)

P.S. Just to not confuse you guys, any code inside the Using(graphics) in my MouseDown event is just to check if a right click falls inside of a created shape. This is in order to open a Properties Dialog that is suppose to be able to change the rotation, location, text, size,width of each drawn shape. I have yet to pass the values, that will be my next monster to tackle.


private void mainFrm_MouseDown(object sender, MouseEventArgs e)
{

initialY = e.Y;
initialX = e.X;
isMoving = true;
using (Graphics g = this.CreateGraphics())
{
if (e.Button == MouseButtons.Right)
{
Point[] ptClick = new Point[] { new Point(e.X, e.Y) };
g.TransformPoints(CoordinateSpace.Page, CoordinateSpace.Device, ptClick);
foreach (Rectangle rect in rectangles)
{
if (rect.Contains(ptClick[0])
{
options.Show();
}
}
}
}
//this.Invalidate();
}

private void mainFrm_MouseUp(object sender, MouseEventArgs e)
{
isMoving = false;
count++;
//rectangle = new Rectangle(movedX, movedY, width, height);
if (rectangleToolStripMenuItem.Checked == true)
{
rectangles.Add(new Rectangle(movedX, movedY, width, height));
//rectangle = new Rectangle(movedX, movedY, width, height);
}
else if (ellipseToolStripMenuItem.Checked == true)
{
ellipses.Add(new Rectangle(movedX, movedY, width, height));

}
this.Invalidate();
}

private void mainFrm_MouseMove(object sender, MouseEventArgs e)
{
if (isMoving == true)
{
//movedX = e.X - initialX;
//movedY = e.Y - initialY;
triangleX = e.X;
triangleY = e.Y;
movedY = Math.Min(initialY, e.Y);
movedX = Math.Min(initialX, e.X);
width = Math.Max(initialX, e.X) - Math.Min(initialX, e.X);
height = Math.Max(initialY, e.Y) - Math.Min(initialY, e.Y);
rectangles.Insert(0, new Rectangle(movedX, movedY, width, height));

}
this.Invalidate();
}


I haven't looked at your code but the overall problem you're having could be solved by making a generic 'Shape' class for all your shapes to derive from and then having your container<Shape>. I don't know very much C#, but I take it this shouldn't be too bad?

I hope this helps ^^
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
Last Edited: 2014-10-28 22:35:35
October 28 2014 22:22 GMT
#10757
On October 28 2014 18:27 delHospital wrote:
Show nested quote +
On October 28 2014 17:46 Manit0u wrote:
On October 28 2014 09:17 delHospital wrote:
On October 28 2014 02:52 Blisse wrote:
What is your stance towards using function names/creating new functions to document the function (when you're creating a new method not necessarily used in other places but makes the intent of the code clearer)

+ Show Spoiler +


def main():
file = getInputFromFile()
n = getCharFromFile(file)

for i to n:
c = getCharFromFile(file)

for j to c:
x[i] = getCharFromFile(file)

doStuff(x)


versus


def doCase(c):
for i to c:
x[i] = getCharFromFile(file)
doStuff(x)

def readCases():
n = getCharFromFile(file)
for i to n:
c = getCharFromFile(file)
doCase(c)

def main():
file = getInputFromFile()
readCases()



Obviously more code but basically that idea. If a group of methods/functions with somewhat complex control flow could be simplified down to a single action, would you prefer wrapping that in a function or prefacing the control flow with a comment.
My advice would be this:

When you split up a function, do it bottom up, not top down. That is, don't cut the function in half, and
def big_f():
f1()
f2()
That doesn't really achieve anything. Instead, try to find small small chunks of functionality that can be meaningful on their own, and extract them from the big function. Those will usually take arguments, process them, and return the result, possibly doing a little bit of IO along the way. If you went with the "cut in half" approach, you would have arrived at two weird looking procedures that take nothing, and return nothing.

To elaborate a bit more:

If you refactor
# does this and that
def main():
...
into
# does this
def this():
...

# (possibly hundreds of lines below, or in a different file)
# does that
def that():
...

def main():
this()
that()

Then it becomes easier to see what main() is about, but it comes with a price: that() becomes harder to reason about, as it depends on the state set up by this().

If you instead refactor it like this:
def f(a, b):
# (play with a and b to get a result)
return result

def g(a, b):
...
return result

def main():
# (code that uses f() and g())

Then, as long as f() and g() are sensible, everything becomes smaller and easier to grasp.


I think that's bad. It's way more convenient to have your main function definition at the top and all the helper function definitions below that. The reason is, while inspecting the file you instantly get to the gist of it and if functions have good names you can instantly tell what it does and only have to look up the helper functions if you really need the specifics. Reading random chunks of code doesn't help you understand what the program is actually doing and what its end goal is, you only get that from reading the main function definition. That's why I think it should be the topmost thing.

TL;DR - abstract --> specific is the way to go, not the other way around.

I'm not talking about how functions should be grouped into modules or about the ordering of function definitions in a file. Yes, putting the helper functions below is probably a good idea, but that's not what my post was about. I was saying that you should primarily extract pure-ish, reusable-ish functions that can be reasoned about in isolation, and that simply dividing a procedure into several smaller ones gains you much less.


The rules I go by (mostly C):
1) Functions ought to be ordered in the same order that their prototypes exist in the header file
+ Show Spoiler +
The alternative is insanity when trying to navigate between the two

2) global (non-static/exported/public) functions go on the top half, then, a comment line seperates that from static/helper functions that go on the bottom half of a file.
+ Show Spoiler +
It should be immediately apparent what the scope of the function you're using is

3) Each file represents precisely one layer of abstraction. No file is too large; no file is too small.
+ Show Spoiler +
When working within a file there shouldn't be a requirement to switch to a different file too often. The exception is when you need to know how that module is meant to be used, or you can use a different module.
If your physical layer definitions reach into thousands of lines of code, then you'll find it's easier to have it all in once place rather than having to search two files. If your intermediary glue code only has one or two functions, then the brevity should make it clear where to look for the actual meat, rather than being confused by having that glue code with the code it's glueing.

4) Length of a function doesn't matter so long as it does exactly what the function definition says it does.
+ Show Spoiler +
If there is no right place to split up a function into helper functions, it shouldn't be split.
Any sufficiently advanced technology is indistinguishable from magic
Manit0u
Profile Blog Joined August 2004
Poland17496 Posts
October 28 2014 22:46 GMT
#10758
On October 28 2014 06:33 Nesserev wrote:
Show nested quote +
On October 28 2014 06:11 Manit0u wrote:
+ Show Spoiler +
Has anyone here ever used the pimcore CMS? I've started working for a new company at the end of last week, got assigned some issues pertaining their project using pimcore, which was set up and solely governed by their former employee. No one knows exactly how it works and I've spent past 2 workdays figuring it all out.

Today I've closed 2 issues, which weren't real issues (client got confused) but found some other things that were disturbing:
1. The code that's on the production server doesn't figure on any of the git branches, it's way ahead of master and all the others and there's no way to push it from the production server...
2. While investigating the code and doing some quick fixes for some real issues (had to do it via vim and ssh console) I've discovered that debug.log file has grown to over 200MB over the course of past 2 weeks, most of which were SQL-based errors (majority of them seemed to be state 2002 - unable to open connection to socket), obviously the file was too large for me to parse thoroughly. Investigating php.log revealed some fatal errors involving PDO exceptions... The debug.log is now growing approximately 1MB/hour since people are beginning to fill in content and test it and I have no idea how to handle it in this unfamiliar environment.

Any ideas where to start fixing this? I'm currently looking for a way to disable debug log entirely as the temporary measure, until I figure out what the next course of action should be.

Sounds like you're really f*cked... good luck with that.


Took me most of the day, but now there are 3 branches on the git (master, development and production), what is on the deployment server now matches perfectly to what's in the git production branch so you can at least work on it externally and pull to the server. I've also managed to get rid of many unnecessary files and got .htaccess to work (previously it wasn't).

I feel like a young god now.
Time is precious. Waste it wisely.
nunez
Profile Blog Joined February 2011
Norway4003 Posts
October 28 2014 23:34 GMT
#10759
my current metastructure(?) is:

abstraction <-> folder <-> namespace
element <-> file <-> (function or class)

most of the abstractions i work with fit on a workspace or two (1~8 vims).
as long as i can switch to a workspace on one screen
to lookup or twiddle with the relevant code, and as long as i'm
not working with too many simultaneously (1~5 abstractions)
it works.
conspired against by a confederacy of dunces.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2014-10-29 01:11:36
October 29 2014 01:11 GMT
#10760
Do you think the future of coding will be 5K to 8K monitors? :3
There is no one like you in the universe.
Prev 1 536 537 538 539 540 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 33m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
SortOf 170
-ZergGirl 58
StarCraft: Brood War
Britney 29904
GuemChi 1328
BeSt 298
Tasteless 274
actioN 222
Mini 199
Horang2 155
Killer 115
Sharp 98
Pusan 95
[ Show more ]
Sacsri 75
Dewaltoss 68
Rush 54
sorry 52
Shinee 39
Barracks 36
ToSsGirL 35
ggaemo 33
Shine 28
ZergMaN 27
EffOrt 20
soO 19
Noble 15
Bale 14
Light 13
Hm[arnc] 8
Dota 2
febbydoto139
NeuroSwarm101
Fuzer 100
canceldota46
League of Legends
JimRising 458
C9.Mang0283
Reynor66
Counter-Strike
olofmeister711
shoxiejesuss490
Super Smash Bros
Westballz16
Other Games
summit1g11793
WinterStarcraft571
ceh9459
crisheroes389
Happy265
Mew2King32
Organizations
Other Games
gamesdonequick586
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 16 non-featured ]
StarCraft 2
• LUISG 29
• Light_VIP 15
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• iopq 2
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• lizZardDota238
League of Legends
• Jankos1020
• Lourlo985
Upcoming Events
The PondCast
33m
OSC
6h 33m
Demi vs Mixu
Nicoract vs TBD
Babymarine vs MindelVK
ForJumy vs TBD
Shameless vs Percival
Replay Cast
14h 33m
Korean StarCraft League
1d 17h
CranKy Ducklings
2 days
WardiTV 2025
2 days
SC Evo League
2 days
BSL 21
2 days
Sziky vs OyAji
Gypsy vs eOnzErG
OSC
2 days
Solar vs Creator
ByuN vs Gerald
Percival vs Babymarine
Moja vs Krystianer
EnDerr vs ForJumy
sebesdes vs Nicoract
Sparkling Tuna Cup
3 days
[ Show More ]
WardiTV 2025
3 days
OSC
3 days
BSL 21
3 days
Bonyth vs StRyKeR
Tarson vs Dandy
Replay Cast
3 days
Wardi Open
4 days
StarCraft2.fi
4 days
Monday Night Weeklies
4 days
Replay Cast
4 days
WardiTV 2025
5 days
StarCraft2.fi
5 days
PiGosaur Monday
5 days
StarCraft2.fi
6 days
Tenacious Turtle Tussle
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.