If this is your first attempt at ABMS, I suggest trying a more modest approach. Complex systems are plenty hard enough to study with just a few variables.
The Big Programming Thread - Page 729
Forum Index > General Forum |
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. | ||
Acrofales
Spain17833 Posts
If this is your first attempt at ABMS, I suggest trying a more modest approach. Complex systems are plenty hard enough to study with just a few variables. | ||
xuanzue
Colombia1747 Posts
in netlogo I put like 5-6variables, and had to quit because the procedural assignation on every variable was too long to code. in c# is quite quicker to code but I miss the features of netlogo to make the agents move. in every tick at most 40 agents are changing, so the pc power is not a problem (yet) | ||
Itsmedudeman
United States19229 Posts
| ||
solidbebe
Netherlands4921 Posts
On May 17 2016 20:28 Itsmedudeman wrote: What book/resources do you guys recommend for writing better code? I started reading Clean Code but I didn't really agree when it came to the point of him saying to keep functions very short to the point where they're 5-6 lines long. Personally, I think when you try to make code too short you just end up creating a deep and unnecessary rabbit hole. It also doesn't seem like a common practice from what I've seen. I dont agree with you. You want to generalize code as much as possible and keeping functions short is a way to go about this. It does depend on the language and what youre working on of course. If you write functions which are significantly longer than 5 - 10 lines there's a good chance your function is taking on more responsibility than it should. | ||
Manit0u
Poland17187 Posts
On May 17 2016 23:39 solidbebe wrote: I dont agree with you. You want to generalize code as much as possible and keeping functions short is a way to go about this. It does depend on the language and what youre working on of course. If you write functions which are significantly longer than 5 - 10 lines there's a good chance your function is taking on more responsibility than it should. +1 Try debugging some 1k+ lines long functions written 10 years ago and you'll see how keeping them short can improve the quality of life. | ||
Fwmeh
1286 Posts
On May 17 2016 20:28 Itsmedudeman wrote: What book/resources do you guys recommend for writing better code? I started reading Clean Code but I didn't really agree when it came to the point of him saying to keep functions very short to the point where they're 5-6 lines long. Personally, I think when you try to make code too short you just end up creating a deep and unnecessary rabbit hole. It also doesn't seem like a common practice from what I've seen. I would strongly urge you to reconcider, w.r.t. Clean Code in general, and specifically regarding short functions. With modern IDEs and refactoring tools, very rarely do you need 10+ lines in a function, even more so in modern languages. In my personal opinion, long methods show a lack of skill, laziness, or both. | ||
enigmaticcam
United States280 Posts
| ||
Nesserev
Belgium2760 Posts
| ||
Acrofales
Spain17833 Posts
On May 16 2016 11:35 xuanzue wrote: to make clear, my problem is the amount of time coding. in netlogo I put like 5-6variables, and had to quit because the procedural assignation on every variable was too long to code. in c# is quite quicker to code but I miss the features of netlogo to make the agents move. in every tick at most 40 agents are changing, so the pc power is not a problem (yet) Yeah, this doesn't make any sense to me. Here is a (local) variable assignment in netlogo: let myvariable 0 and a global is the same with set, instead of let, and you have to declare it global. Here is the same in c++
Now I won't claim that netlogo is compact, or a great language to code in. It's a very simple language meant for exactly one thing: allowing non-programmers to build social simulations. But it's pretty good at what it does. Maybe I'm not understanding your problem, though... | ||
Manit0u
Poland17187 Posts
| ||
spinesheath
Germany8679 Posts
var a = b.Where(condition).ToList();but I don't accept var a = b[i++];. There definitely are times when longer methods are justified. This occasionally happens when the code is performance-critical (always profile first). And sometimes you just need to do 10 steps at an equal level of abstraction in a certain order without a reasonable grouping. But for every long method there should be a bunch of short ones. Just write your code without worrying about length at first. But if you are done and can select a couple of instructions and give those instructions a good name, chances are they should go into a seperate method. And if you then notice that you extracted a bunch of methods that deal with the same stuff, chances are they should go into a class of their own. About the common practice argument: common practice does not guarantee quality in coding. The average programmer sadly isn't very good, and neither are some of their common practices. | ||
xuanzue
Colombia1747 Posts
On May 18 2016 01:33 Acrofales wrote: Yeah, this doesn't make any sense to me. Here is a (local) variable assignment in netlogo: let myvariable 0 and a global is the same with set, instead of let, and you have to declare it global. Here is the same in c++
Now I won't claim that netlogo is compact, or a great language to code in. It's a very simple language meant for exactly one thing: allowing non-programmers to build social simulations. But it's pretty good at what it does. Maybe I'm not understanding your problem, though... assigning 50k variables (60 per agent) is much more quick with c, mostly because I can use for/switch/while/if, to procedurally assign them. is there any method to import a big DB in netlogo and automatically assign all the variables? that will solve many of my problems tho. my last attempt with nlogo was like: + Show Spoiler +
| ||
Acrofales
Spain17833 Posts
On May 18 2016 09:27 xuanzue wrote: assigning 50k variables (60 per agent) is much more quick with c, mostly because I can use for/switch/while/if, to procedurally assign them. is there any method to import a big DB in netlogo and automatically assign all the variables? that will solve many of my problems tho. my last attempt with nlogo was like: + Show Spoiler +
I still don't understand the problem. Setting 50k variables is no harder than setting 60, assuming you have some configuration parameters that allows you to set your 60 variables per agent based on some configurations. While Netlogo doesn't have switch statements, it does have ifelse, which'll do in a pinch. It also has loops, so that doesn't seem to be the problem. You can do something like:
Unfortunately, this will accumulate a godawful number of closing brackets at the end, because you have to nest them. But it's a valid way of doing this. You can also simulate a switch statement (if it is at the end of your procedure) with stop (which is equivalent to return, rather than break):
To help you with your specifics, I need more of an idea of what you're trying to do. Your code snippet seems fine, but I agree it'll get pretty shitty pretty quickly. There is probably an easier way of doing it, if there is some underlying meaning to CLS, UNV, etc. I assume there is, otherwise the work would be equally onerous in any other language. | ||
xuanzue
Colombia1747 Posts
1 agent would be the aggressor trying to assimilate thousands of agents. every agent has a different behavior, some will attempt to fight by themselves the threat, others will instead flee and warn near agents. for example CLS are the kind of weak/flee and their variables will reflect that. this is my actual map in c#: + Show Spoiler + ![]() and this was my map in netlogo: + Show Spoiler + ![]() the nodes 37-40 are the inner triangles the nodes 55-58 are the other triangles For example UNV will move between those triangles. in the example I breed 128 UNV turtles, but i needed the first 32 to stay moving between 34 and 55, the next 32 between 35 and 56 and so. when I was working in netlogo I only had 7 variables and 8 kind of turtles that share some similarities. Now in c# I have 23 kind of agents (turtles) and 20 variables ATM( but I know the variables can expand to 60) in c# I first run a program to make a DB of variables and then I import it in the model. I'm thinking to change this to OOP + Show Spoiler +
also I have another DB for possibles routes for every agent. I have no big experience programming, so any info/docs to make things easier is appreciated. thanks for stay answering me ^^ | ||
Djagulingu
Germany3605 Posts
| ||
Manit0u
Poland17187 Posts
On May 18 2016 19:38 xuanzue wrote: my objective is: 1 agent would be the aggressor trying to assimilate thousands of agents. every agent has a different behavior, some will attempt to fight by themselves the threat, others will instead flee and warn near agents. for example CLS are the kind of weak/flee and their variables will reflect that. this is my actual map in c#: + Show Spoiler + ![]() and this was my map in netlogo: + Show Spoiler + ![]() the nodes 37-40 are the inner triangles the nodes 55-58 are the other triangles For example UNV will move between those triangles. in the example I breed 128 UNV turtles, but i needed the first 32 to stay moving between 34 and 55, the next 32 between 35 and 56 and so. when I was working in netlogo I only had 7 variables and 8 kind of turtles that share some similarities. Now in c# I have 23 kind of agents (turtles) and 20 variables ATM( but I know the variables can expand to 60) in c# I first run a program to make a DB of variables and then I import it in the model. I'm thinking to change this to OOP + Show Spoiler +
also I have another DB for possibles routes for every agent. I have no big experience programming, so any info/docs to make things easier is appreciated. thanks for stay answering me ^^ Just 2 things that come to mind after quickly glancing over it: 1. You should really split this into several functions. 2. Perhaps it could be much more brief if done recursively? | ||
Deleted User 101379
4849 Posts
foreach ($messages as $key => $message) I don't think that works as they think it works... I have to rewrite the whole code they wrote in the last two weeks in two days because it's pure trash that doesn't even do what the task I gave them required, despite me making diagrams on the whiteboard and explaining everything twice while showing the code parts that needed to be changed and added. | ||
phar
United States1080 Posts
| ||
Deleted User 101379
4849 Posts
On May 19 2016 11:55 phar wrote: Does your team not enforce code reviews before submission? :S That sounds painful. I found that during the code review. I had let them work on the project in their own git branches for two weeks, since I had a few other urgent things to take care of and I wanted to see how they work without someone constantly looking over their shoulder. On Friday they said "yeah, we're finished, everything is tested and works" and on Tuesday my week was ruined when I checked out their branch for review. I would usually tell them what they did wrong and how to fix it, but in this case it's pretty much "everything" and we need that done by Monday, so I'll just finish the project myself and then show them how I wanted it to be. I did check their progress 2-3 times during that period, pointing at things that still need to be changed and it turned out that they didn't even change the places I showed them directly in the code. I probably should have checked on them more often, but I have neither the time nor the will to babysit them every day. At least now I know that I can't give them anything more than menial work. I would fire them, but then we'd be 1.75 programmers (I've recently been promoted to project manager, though I'm still also programmer until we can find a replacement) and a trainee working on fairly large projects. For now we can at least still use them for the boring stuff that doesn't require any creative thought until we find someone who can actually program in a way that doesn't make my IDE cry. | ||
Keniji
Netherlands2569 Posts
On May 19 2016 00:58 Morfildur wrote: The joy of working with student programmers: foreach ($messages as $key => $message) I don't think that works as they think it works... I have to rewrite the whole code they wrote in the last two weeks in two days because it's pure trash that doesn't even do what the task I gave them required, despite me making diagrams on the whiteboard and explaining everything twice while showing the code parts that needed to be changed and added. So what did they try to do? Is $messages some array of collected errror messages? | ||
| ||