Open Side Menu Go to the Top

04-11-2015 , 05:35 AM
nvm I have no idea what I'm talking about and it appears to be a safety thing.

Last edited by jmakin; 04-11-2015 at 05:52 AM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
04-11-2015 , 05:57 AM
This was the best answer I found from stackoverflow for a question that spawned from your question as to why the remove() method even exists in the first place in Iterator, and I got this:

Quote:
Iterator is able to remove elements during iteration. You cannot iterate collection using iterator and remove elements from target collection using remove() method of that collection. You will get ConcurrentModificationException on next call of Iterator.next() because iterator cannot know how exactly the collection was changed and cannot know how to continue to iterate.

When you are using remove() of iterator it knows how the collection was changed. Moreover actually you cannot remove any element of collection but only the current one. This simplifies continuation of iterating.

Concerning to advantages of passing iterator or Iterable: you can always use Collection.unmodifireableSet() or Collection.unmodifireableList() to prevent modification of your collection.
to answer your question it appears my initial suspicion was right and that an add() method would just be redundant and unnecessary, specifically in the case of maps, which you'd never iterate through anyway.

if you don't get what I'm getting at, which I barely do, just sum it up to Java gobblydegook.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-11-2015 , 06:52 AM
Regarding add() being redundant: Not really, everything applying to remove() in the StackOverflow quote also applies to add() re: ConcurrentModificationException.

The add() method is also not part of the standard Iterator interface, only of ListIterator. The iterators returned by map.keySet().iterator() or map.values().iterator() probably don't implement ListIterator anyway.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-11-2015 , 07:46 AM
Quote:
Originally Posted by Ryanb9
i can understand why you would use iterator.hasNext() and interator.next() which is basically for the for-each loop, but other than that I don't see the point. why would u make an iterator instance and then use that instead of just doing it normally.
Sometimes the iterator can provide more efficient implementations. For instance in a LinkedList you can remove/add at the current position in O(1) using the ListIterator, performing the same operations using add(index,element) / remove(index) / remove(element) on the list would run in O(n).
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-11-2015 , 11:06 AM
So obviously don't be stupid and enter information here and get phished, but this site has apparently scraped 100% of the publicly available content on 2+2 and in continuing to update their site:

www.gambletalks.com
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-11-2015 , 11:09 AM
It appears they are using NGINX vs 2+2's use of Apache.

I haven't looked too hard yet, but it also looks like they are using Cloudflare and hiding where the site is hosted.

Cloudflare has a pretty open policy of allowing ddos'ers to use it and such so I wonder how hard it is going to be to take down this site.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-11-2015 , 11:20 AM
Yea I saw that earlier. Looks like thread about it is here http://forumserver.twoplustwo.com/55...talks-1524650/

Edit: the scraping seems too fast.. Right when I posted its already on there...
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-11-2015 , 11:31 AM
Echo!
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-11-2015 , 02:18 PM
Quote:
Originally Posted by plexiq
Regarding add() being redundant: Not really, everything applying to remove() in the StackOverflow quote also applies to add() re: ConcurrentModificationException.

The add() method is also not part of the standard Iterator interface, only of ListIterator. The iterators returned by map.keySet().iterator() or map.values().iterator() probably don't implement ListIterator anyway.
Quote:
Originally Posted by plexiq
Sometimes the iterator can provide more efficient implementations. For instance in a LinkedList you can remove/add at the current position in O(1) using the ListIterator, performing the same operations using add(index,element) / remove(index) / remove(element) on the list would run in O(n).
Thanks for clarifying, that was bugging me last night.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-11-2015 , 06:45 PM
Looked ahead at my 2nd level c++ class's final exam prep info. Our entire course covers:
  • Pointers
  • Inheritance
    • Polymorphism

This had to be a 16-week course? I mean, pointers was basically a refresher with a little more info about how they work.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-11-2015 , 06:58 PM
I was watching a video the other day and the speaker had this quote:

"No function or method should be more than 7 lines. If you show me one, I'll prove to you that it is wrong in some way."

As I've been refactoring my old code, I've been aiming to get each function down to 7 lines. For the most part, I'm dissolving things down into smaller patterns and removing strung together functions into separate functions which are 3 lines max.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-11-2015 , 07:23 PM
Quote:
Originally Posted by daveT
I was watching a video the other day and the speaker had this quote:

"No function or method should be more than 7 lines. If you show me one, I'll prove to you that it is wrong in some way."

As I've been refactoring my old code, I've been aiming to get each function down to 7 lines. For the most part, I'm dissolving things down into smaller patterns and removing strung together functions into separate functions which are 3 lines max.
we've had this argument here before, and many disagree with the advice, but i think that, basically, it's correct.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-11-2015 , 07:27 PM
To continue this refactoring issue: the starting file was 147 LOC and now it is 203. Once I get rid of some of the dead code, it will probalby go down to 190 or so, but I've added 50 LOC to the file. While it is certainly "refactored" and tons of repeating code is gone, I still wonder how much the goal of refactoring is supposed to minimize LOC count.

While I *could* make a bunch of code that generates code, I'm always afraid of doing that since it isn't obvious how much the final program will look. I came across this in my most recent project where I generate 60 KLOC, but these extra files superfluous if I was to push the code-generating function directly into the database instead of files (generating "invisible" code because pushing the output is causing encoding errors). Part of it is visual and easier to demonstrate / document, but totally unneeded. Where does clarity go out the window in lieu of some murky definition of better, where "better" in this case would be the code is generated and seen once it is fully executed? I ask because I once showed a project to someone and their first comment was "wow, that's pretty small." I didn't want to explain that this 30 LOC here could generate nearly unlimited code, and in fact, with a bit of modification, it will generate over 100 KLOC, which I'm too lazy to write by hand, obviously.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-11-2015 , 07:28 PM
Quote:
Originally Posted by gaming_mouse
we've had this argument here before, and many disagree with the advice, but i think that, basically, it's correct.
Sorry. I'll look for that then.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-11-2015 , 07:37 PM
Some examples to chew on would be helpful.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-11-2015 , 07:46 PM
Quote:
Originally Posted by daveT
To continue this refactoring issue: the starting file was 147 LOC and now it is 203. Once I get rid of some of the dead code, it will probalby go down to 190 or so, but I've added 50 LOC to the file. While it is certainly "refactored" and tons of repeating code is gone, I still wonder how much the goal of refactoring is supposed to minimize LOC count.
yeah, i think generally good refactorings decrease LOC. not always, but usually. probably in your case you did improve the code, but it could improved even more, getting you both good structure and less code.

as suzzer said, it's a conversation that's kind of worthless without examples, but a 190 line file is probably too much. maybe you could post a coherent portion?

btw, the codereview stackexchange site is pretty great, and i'd recommend posting there too to hone your refactoring skills. not sure what the guidelines are for length -- i know 50 lines would be fine, 100 probably would, not sure beyond that.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-11-2015 , 07:53 PM
Quote:
Originally Posted by daveT
I didn't want to explain that this 30 LOC here could generate nearly unlimited code, and in fact, with a bit of modification, it will generate over 100 KLOC, which I'm too lazy to write by hand, obviously.
Just out of interest, what is this project about? I can't think of an instance where it would make sense to generate 100 KLOC using 30 LOC unless you need to work around some ridiculous language restrictions. But I'm most likely missing something here.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-11-2015 , 08:22 PM
The code generation is an extension of this:

I have a colleciton of spreadsheet files that I pulled from Amazon here:

https://github.com/dt1/omark/tree/ma...-flat-files/us

As you can tell, I have a lot of them and I'd be insane to do convert all of this by hand, so I have these two files that I use to generate SQL:

This code
https://github.com/dt1/omark/blob/ma...flat-tables.py

generates all of the SQL you see here:
https://github.com/dt1/omark/tree/ma...-tables/tables

And this code
https://github.com/dt1/omark/blob/ma...-insertions.py

generates all of the SQL you see here:
https://github.com/dt1/omark/tree/ma...les/insertions

For those who don't see it, this is a collection of constraint tables with proxy tables, so instaed of this:

Code:
create my_table (
      my_id int primary key,
      coolio varchar check (coolio in ['a', 'b', 'c'])
);
I do this:

Code:
create my_constraint (
      coolio varhcar primary key
);

create my_table (
      my_id int primary key,
      coolio varchar,
      foreign key (collio) references my_constraint (coolio)
);
The scripts generate the tables and constraint tables.

This causes a few issues. First, I have to add some script, which is simple
>$ for f in *.sql; do psql omark < $f; end; ## I think it is this, but you get the point

but this ended up causing a ton of encoding issues. For some reason, some hex characters are added to the beginning of some of these files and they won't take, kiling off that transaction, which causes bugs furhter down the chain.

It is nice to have the SQL files there for documentation purposes, but I don't see much point of it beyond that. Catching errors and debugging is fairly trivial.

The next step would be generating the main product tables from the excel files. Capturing the types is simple and, aside from a little bit of manual intervention, won't be an issue.

So, I have all of these files that make it obvious what you are getting, but I don't think having them there does anything for the program. I have no intention of ever using them. Updating the system would be a total nightmare if I constantly pushed to .sql files and attempted to run update scripts like this. I just don't see the point of having the .sql files at all, but from an end-user perspective, I wouldn't know what I am getting without some sort of reference material, and who the hell wants to read a bunch of UML documentation?

I often think about stuff like this, especially when I see a collection of functions that are nearly the same aside from a few odd lines of code (the SQL files are identical).

This would extend a bit to the Clojure code I'm looking at, but I want to sanity check this assumption before continuing.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-11-2015 , 08:47 PM
Quote:
Originally Posted by daveT
"No function or method should be more than 7 lines. If you show me one, I'll prove to you that it is wrong in some way."
I always read this from ruby gurus. Does it apply to other languages/paradigms? Say for example, nodejs: https://github.com/sahat/satellizer/...node/server.js

I kind of like being able to just follow the flow of the program inline even though it looks like a mess.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-11-2015 , 08:49 PM
We have a function as the last step in the middleware chain of node/express that sets a bunch of properties for the Jade template or angular client-side code to use. I can't imagine how we could possibly get that down to seven lines.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-11-2015 , 08:57 PM
add another 5 functions and a library to read the properties from a config file obv
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-11-2015 , 09:16 PM
Quote:
Originally Posted by gaming_mouse
we've had this argument here before, and many disagree with the advice, but i think that, basically, it's correct.
I've probably changed my position a number of times on this but I'm currently at: "Yeah, I basically agree (except for a number of special cases). But you can get many methods > 7 lines of code that are only trivially worse than the <= 7 lines of code implementation and I just can't understand why anyone would think something like this is that important as a hard and fast rule.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-11-2015 , 09:19 PM
Quote:
Originally Posted by e i pi
I always read this from ruby gurus. Does it apply to other languages/paradigms? Say for example, nodejs: https://github.com/sahat/satellizer/...node/server.js

I kind of like being able to just follow the flow of the program inline even though it looks like a mess.
yeah, the login functions are a mess.

pretty much whenever you have stuff like:

Code:
if (blah)
   //long mess of crap
else
   // long mess of crap
you can improve it by pulling the long bunches of crap into their own functions, so you have:

Code:
if (blah)
   conciseFunctionNameDescribingWhatMessofCrapDoes();
else
   anotherDescriptiveFunctionName();
The complaint that "now I have to jump to another function to see what it does" is misguided. One, your editor should make that trivial. But two, and this is more important, your mind only focuses on one level of abstraction at a time. That is, either you trying to understand what the function does on a high level, in which case the refactored version is much clearer, because the details of the messes of crap are noise; or you are interested in the details of one of those messes of crap, in which case you'd rather be focusing on just that, and viewing it 3 or 4 indentations deep within a context that is not relevant for your current level of focus is just noise.

Last edited by gaming_mouse; 04-11-2015 at 09:30 PM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-11-2015 , 09:23 PM
Quote:
Originally Posted by suzzer99
We have a function as the last step in the middleware chain of node/express that sets a bunch of properties for the Jade template or angular client-side code to use. I can't imagine how we could possibly get that down to seven lines.
do you mean the function is essentially setting a bunch of config variables, each on their own line?

i think that's a valid exception to the rule, although you could potentially group the config variables by categories, or you could do the config in config file. but it's far less important in that case.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-11-2015 , 09:28 PM
Quote:
Originally Posted by jjshabado
I've probably changed my position a number of times on this but I'm currently at: "Yeah, I basically agree (except for a number of special cases). But you can get many methods > 7 lines of code that are only trivially worse than the <= 7 lines of code implementation and I just can't understand why anyone would think something like this is that important as a hard and fast rule.
i basically agree. i'm not a nazi about the rule, but i do find it's a pretty reliable heuristic. it becomes even more reliable when combined with the "one level of indentation, maaaaaybe 2 sometimes" rule.

i think it's important to understand the motivation of the rule, to know when it's okay to break it. the rule's purpose is to prevent the mixing of different levels of abstraction, and to make complex things clear by grouping them into appropriate chunks and naming them well.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

      
m