« first day (446 days earlier)      last day (3588 days later) » 

9:00 AM
That double cast is especially ugly
 
youch...
but the idea is nice, you have something like a Map<Class<?>, Func<Object, String>> in disguise there...
 
Yeah somewhat
But using Java 8 I'd still do it like this I think
 
why do you downcast to object btw?
it should be fine, if AlphaModelConverter / BetaModelConverter implements ModelConverter<Object,String>
 
@Vogel612 They implement ModelConverter<AlphaModel, String> though
I've got a new version
figuring the chat is still empty, so I can still spam it
@SuppressWarnings("unchecked")
public enum ModelConverters {
    INSTANCE;

    private final Map<Class<?>, ModelConverter<?, String>> modelConverters = new HashMap<>();
    {
        modelConverters.put(AlphaModel.class, new AlphaModelConverter());
        modelConverters.put(BetaModel.class, new BetaModelConverter());
    }

    public static <T> String convert(final T input) {
        ModelConverter<?, String> modelConverter = ModelConverters.INSTANCE.modelConverters.get(input.getClass());
        if (modelConverter == null) {
There's probably a few things/verifications I forgot
 
it looks like we could rename HassanSupport to CodeBouncing Area
 
9:05 AM
modelConverters.put(AlphaModel.class, new AlphaModelConverter()); are you smart enough to write this? Or do you want an explicit check on the type
When creating the matting
 
so you would try to get away from the Factory Pattern there?
 
@skiwi You require at least 53 Int to write this line of code.
 
@Vogel612 Factory pattern... as in? I think the model converter is still a factory pattern, kind of
 
no it isnt...
 
And I figure a way to make the modelConverters.put safe
 
9:06 AM
you just defer the conversion to some implementation you abstracted away..
in fact what you wrote here is the ModelConverter..
in fact you render the interface useless...
 
Yeah, but it doesn't know how to convert
 
that's irrelevant for that matter..
a Factory gives the caller an instance he can operate...
while this (instance returning) is overkill for the problem at hand (seeing your code work it out so nicely)
you did something different...
 
This will turn into some Dutch over engineering right now...
 
definitely looks like it..
 
That'd be an interesting point to make on Code Review. Your code is over-engineered, make it simpler. Handle less future cases. Be more dirty. Weave a touch of madness into your design.
 
9:12 AM
where was the computerphile vid on DateTime again?? ;)
 
1. Find over engineered code. 2. Make it very simple. 3. Over engineer it again.
I almost got it, the only issue right now is that it doesn't compile.
And I have no clue why :(
 
@skiwi does it say something?
 
It offered a cast actually, and it fixed it, though I need to check the consequences of it
Newest version:
@SuppressWarnings("unchecked")
public enum ModelConverters {
    INSTANCE;

    private final ModelConverterBacking<String> modelConverterBacking = new ModelConverterBacking<>();
    {
        modelConverterBacking.put(AlphaModel.class, new AlphaModelConverter());
        modelConverterBacking.put(BetaModel.class, new BetaModelConverter());
    }

    public static <T> String convert(final T input) {
        ModelConverter<T, String> modelConverter = INSTANCE.modelConverterBacking.get((Class<T>)input.getClass());
It still has one unsafe cast though
 
0
Q: Async function with slow web reference(web service) slowing down webpage

HenrikP(Repost from SO since I got recommended to post it here instead) tl;dr: Is there a way to make a threading/async post with a web reference not slow down the whole website just because the web reference takes a long time to return a response? I have a send email function that gets posted async ...

0
Q: Logging strategy setup

xvdiffI finally set up my logging infrastructure to work as desired, however I feel like I had to do quite a lot things just to fulfill a few requirements. Now I'm worried if my approach has major drawbacks, e.g. in performance or stability, so I need your help! Requirements Logging to multiple outp...

 
I think it's safe until it fails in production.
I don't 100% understand it
I have final T input, whose class should be Class<T>, correct?
But input.getClass() returns Class<?>, because it only knows that T extends Object
So casting to Class<T> should always be safe
 
9:22 AM
What if it was null?
 
@Pimgd If your getClass() returns null, then you screwed up :P
Or you input null?
 
no, input
 
Exception in thread "main" java.lang.NullPointerException
	at testproject8.vogel612.overengineering.cr57768.ModelConverters.convert(ModelConverters.java:19)
Which is correct behaviour
 
@skiwi actually it should depend...
my current "AbstractConverter" will return ""...
Object thing = (Object)null;
thing.toString();
IIRC that should return ""
OTHO:
Object thing = null;
thing.toString();
should throw NPE.
 
Can't be done here I'm afraid
 
9:28 AM
@skiwi I will not pass null in either way, and if I do it's safe to throw NPE ;)
 
0
Q: Async function with slow web reference(web service) slowing down webpage

HenrikP(Repost from SO since I got recommended to post it here instead) tl;dr: Is there a way to make a threading/async post with a web reference not slow down the whole website just because the web reference takes a long time to return a response? I have a send email function that gets posted async ...

this reeks of example code
am I right or is there enough code provided
 
0
A: More German overengineering™ - Class mappings and factories

skiwiIn response to your German overengineering™, I raise you some Dutch overengineering™. I have managed to get rid of almost all unsafe things, like creating instances via reflection etc. My implementation has one unsafe cast, but I'll explain that it's no issue as we go. I've decided to leave the...

200 rep, here we come!
@Vogel612 It works, it's alive!
 
@skiwi TBH I don't see your approach as superior to mine...
maybe my interface name was just plain sh*t....
it probably should have been CollectionStringifier
 
We always think our own code is best :)
 
9:44 AM
I don't, but that's because I got to eat humble pie recently
 
I'll also add a few points why I think your version is suboptimal.
 
Fleshing out a game I wanted to make, I was gonna post it on some forum asking for feedback, when I playtested it and realized it would take more than 10 times to make than what I had expected due to content creation, and then I'd still have to balance it
 
I think I'll get rid of that BrokenCodeException, because it isn't.
 
BrokenCodeException is for developer failure. It should be impossible to cause by user failure.
Given that convert is public, it's not developer failure
I'd use BrokenCodeException for when you're using a specific nasty language feature relying on a compiler or JVM hiccup... (okay that's not very common in Java) and it only works because some external force is cleaning your crap
 
I've updated the answer slightly.
 
9:49 AM
It'd be nice to know it fails because your external help is gone, and not because of your first change you've made for the day
 
@Vogel612 I think the bottomline of my points are that you are using features which are better to be avoided. (Enum for things where they are not supposed to be used for and reflection)
@Pimgd I think a BrokenCodeException was valid when putting the mappers, but I check those at compile time now
I think I'll get my answer reviewed as well :P
 
@skiwi you seem to misunderstand the intention behind the code...
usage example:.
 
I forgot to explain how to call it in my answer, added it despite what you are saying now
 
 AlphaController implements Serializable {
     private static final ModelConverter<T> converter = ModelConverterFactory.createConverterFor(AlhpaModel.class);

     private final Collection<AlphaModel> items;
     public AlphaController() {
           items = AlphaService.loadAll();
     }
     public Collection<String> getItemRepresentation() {
            return converter.convert(items);
     }
  }
 
Eager to hear how it should be then?
 
10:02 AM
monking @all (quick peek and back gone ;)
 
Monking @chillworld
@Vogel612 That's no big issue, or is it?
 
well your ModelConverters could expose an overload for Collection, but that is beside the point...
 
return items.stream()
    .map(ModelConverters::convert)
    .collect(Collectors.toList());
 
Point is, that I have an instance that is usable by the Caller.
 
(In Java 8 style I know)
I see what you are saying, but do you need to know that instance?
 
10:04 AM
It's actually irrelevant, wether I have that instance or not...
initially the converter also allowed converting back...
 
It's also still possible to obtain the converter from my current code
 
but then we could have exposed a different method to forward...
 
(With some modifications of course)
 
what makes your solution different from bowmores answer then?
 
public static <T> ModelConverter<T, String> getConverterFor(final Class<T> clazz) {
    return INSTANCE.modelConverterBacking.get(clazz);
}
Could be added for example
 
10:08 AM
you abstract the instance even further away...
 
I'm using somewhat of a different approach
I do think using enums is bad for it
 
yea, you have that Map starting point
 
And compile time safety
 
and then create a utility proxy...
and that utility proxy internally uses a simplified factory pattern to provide access to the proxied Converters..
 
Converting a whole collection at once is I think only gonna work when you add a method for it
 
10:10 AM
@skiwi you need to iterate the items either way...
 
I'd always try to abstract away as much as possible and use meaningful names for all classes
 
whether you do that in the controller or converter is irrelevant..
I think a proxy is overkill...
 
@Vogel612 I think this part (turning a Collection<T> into a Collection<String> is really the problem of that class, and not of the converter class
If you find it often, then create a utility class to do exactly that
Though Java 6 will give you a headache with that :/
 
not really...
just loop over the collection and convert every item "by hand"...
 
Can't specify method references or lambdas, so will create headaches
 
10:12 AM
for you maybe..
but would definitely be easier in Java 8 ;)
 
I can imagine it is easier to do it in Java 6 with your experience therein
 
if it weren't for java 6 i probably would have changed my AlphaController#getItemsRepresentation..
 
You could still create your own "functional" interfaces
The code will not look pretty at first glance, but the logic will be way easier
 
 return items.stream().map(AlphaModel::getAttribute()).collect(Collectors.toList());
 
Is your string representation really that easy?
Or is it more sophisciated
private final ModelConverterBacking<String> modelConverterBacking = new ModelConverterBacking<>();
{
    modelConverterBacking.put(AlphaModel.class, alphaModel -> "ALPHA");
    modelConverterBacking.put(BetaModel.class, betaModel -> "BETA");
}
 
10:16 AM
@skiwi that depends on the ModelClass.
 
^^ also works
On Java 8 that is
 
okay that's cheating..
 
Personally I just use Function<I, O> then or some sort
 
modelConverterBacking.put(AlphaModel.class, alphaModel -> alphaModel.getAttribute());
works too, right?
 
And then I can define the actual static methods wherever I want
@Vogel612 Yep
Real life example:
public class OrganizationBuilder {
    private final static Map<OrganizationField, Predicate<String>> DEFAULT_VALIDATION_MAPPING = new HashMap<>();
    static {
        DEFAULT_VALIDATION_MAPPING.put(IBAN_NUMBER, IbanNumberValidator::validate);
        DEFAULT_VALIDATION_MAPPING.put(IS_PARENT, isParent -> (isParent.toUpperCase().equals("Y") || isParent.toUpperCase().equals("N")));
        DEFAULT_VALIDATION_MAPPING.put(VAT_NUMBER, VatNumberValidator::validate);
    }
 
10:18 AM
 
public class IbanNumberValidator {
    private static final String IBAN_NUMBER_REGEX = "(?i)^[a-z]{2}\\d{2}[a-z0-9]{11,}$";
    private static final Pattern IBAN_NUMBER_PATTERN = Pattern.compile(IBAN_NUMBER_REGEX);

    private IbanNumberValidator() {
        throw new UnsupportedOperationException();
    }

    public static String getRegex() {
        return IBAN_NUMBER_REGEX;
    }

    public static boolean validate(final String ibanNumber) {
        Objects.requireNonNull(ibanNumber, "ibanNumber");
 
why not make the IbanNumberValidator final?
 
It's similarish to your case
and it's just a bunch of randomly defined methods here
I could also put all validators in a single class
@Vogel612 Because it should be ;) nice spot
 
insta-review ;)
 
What I showed in my answer, is I think the closest I can reasonable get in Java 6 wanting to use Java 8 concepts
 
10:21 AM
Well in core you are suggesting, that I insert another abstraction layer in there, and define a Proxy class..
and that is unrelated to java8 concepts themselves...
 
I think it's good to abstract as much as possible
 
the Java 8 api just makes use of that concept more frequently and obviously than the java 6 / 7 api.
 
I'm not that familiar with proxy pattern though
 
congrats you just implemented one (if that pattern exists, and if proxy means what I think it means)...
maybe Router is a better word than Proxy....
it kinda combines both concepts into one..
 
What part is it that you are referring to?
I don't really have a clue of what exactly I'm all doing in software related terms
 
10:26 AM
well the Router decides where your "request" (convert my Object) goes, and the Proxy hides from the asker and answerer who exactly asked/answered now,..
 
What about the ModelConverterBacking<String> over the HashMap<>? I know the term composition over inheritance, which I'm using.
I'll use the pattern now
 
In fact your ModelConverterBacking is a wrapper for Map<Class<?>, ConverterClass</* */>>
 
pff slacker, eating lunch a couple minutes before it's actually lunchtime
 
and that means you are running on both inheritance and composition...
@Pimgd #define lunchtime
 
response:{now}
 
10:31 AM
For when I'm back: What part(s) do you consider too much abstraction and would you remove?
@Pimgd I have vacation :) ha
 
I don't, yet I'm still in chat! Ha
oh wait, joke's on me =/
 
Guys, I cannot understand this code: return ! $this.attr('data-move');
(JavaScript).
 
Inverses the boolean value stored in data-move
Is what I think
 
response: also:{now}
 
and back
@Vogel612 Will you first migrate to Java 7 before 8?
 
11:02 AM
Monking
 
Monking Evening @SimonAndréForsberg!
 
aaand back
 
I think it's getting hot here... My PC is not doing much, but the fans are starting to run on higher speeds.
 
@skiwi I doubt I will migrate at all...
my direct superior still regularly labels our project as JEE 7 application..
concerning "too heavy abstraction". You hide the ModelConverter Interface away...
I think that might already be a step too much..
also: 159 little dinosaurs on the wall ...
 
How can he label it as Java 7 if you're using Java 6, whaat?
@Vogel612 You can also expose it
 
11:15 AM
because it's a she...
and she's incompetent.
 
Kick her out and take the lead! Pitchforks!
 
@Pimgd If someone changes an argument name, they've changed the method name. The arguments have internal and external names, and only changing the external argument name changes the method name and requires fixing the places where the method is called.
 
not that simple as a trainee...
I am just gonna have to put up with this for another 6 months, so it will be fine.
 
@nhgrif I'd hate a language like that
 
You're working on it from an internship perspective only? Like you need to survive the 6 months and then you're gone?
 
11:17 AM
@nhgrif is that similar to the concept of passing parameters in vba
 
Or is it just a job where you are a trainee, but then I don't get the 6 months part
 
@skiwi I am a trainee..
 
What we have instead of convertMilesToFeet(argument); is instead convertToFeet(miles:argument); where a clear distinction is made between a description of what the method does, and the parameters on which it acts.
 
currently in the second year of my training.
overall scheduled duration: 2.5 years...
 
I'm a bit confused, when you start working at a company, then you also start out as a trainee, is that what you are?
 
11:18 AM
Changing to convertToFeet(inches:argument); from the former involves the same hassle as would be involved in changing to convertInchesToFeet(argument);
 
after that, even if I stay with the company, my superior changes, and hopefully becomes someone better.
you don't usually start as a trainee, when you apply for senior developer...
 
Ah, it's a big company that follos its own rules at all times?
 
The difference is that with the named parameter, it becomes clear what each parameter does.... you can't mistake parameters.
 
do you know the German concept of "Ausbildung"
 
I meant when you start working right out of school, was my bad :P
 
11:19 AM
exactly that.
 
Particularly when there are more than one parameter.
 
@Vogel612 Not really
 
in Germany you can finish school with different "levels" of education. These are called "Abschlüsse"..
 
@skiwi I know I'm up late, but not that late!
 
the different levels are: "Hauptschulabschluss" (after overall 8 years of school), "Realschulabschluss" (overall 10) and "(Fach-)Abitur" (after 12/13 years)
with "Abitur" you can go to University.
 
11:22 AM
From where do you guys start counting?
 
some Universities also allow "Realschulabschluss" as entry certificate, but that's seldom and you will have to complete additional ceremonies.
 
Education systems are so different everywhere
 
grade schoolers (6 years old)
then school begins.
 
on 6? :o
I think it's at 4 here
 
first 4 are "Grundschule", the rest is "weiterführende Schule"
 
11:24 AM
Here it's from roughly 4y to 12y (8 years), the elementary school, and you cannot do anything with that
 
maps to our "Grundschule" that goes from 6y to 10y..
 
then lowest grade is "VMBO", which costs another 4 year, and then you are certified for physical work
 
that fits to "Hauptschule"
 
altenratively to the "VMBO", you have "HAVO" (5 years), and "VWO" (6 years)
both are theoretical, latter is required for university
 
fits the bill in germany too..
just called different and times are different.
 
11:26 AM
so the "VWO" is "Realschulabschluss"
 
HAVO is..
 
hmm
 
if you can start working as a trainee then
 
@Pimgd Does it help to know that convertToFeet(miles:argument); and convertToFeet(inches:argument); would count as different methods even if the return type and the type of the single argument are the same? This is because miles or inches is considered part of the method name making these two methods distinct.
 
Abitur is the central exam, right?
 
11:26 AM
yep.
Realschulabschluss is also central though..
the problem is, the exams are different for each "Bundesstaat"
 
@nhgrif Then you've just murdered function pointers and I hate your language
 
And then I think in the netherlands it's even more complicated
@Vogel612 much fun there
 
germany is comprised of 16 Bundesstaaten.
btw. after Realschule you can go for "Fachabitur". they only qualify you for certain fields of study.
 
ok
 
there's also "allgemeines Abitur". with that you can study what you want.
 
11:28 AM
Here there is also the "MBO", "HBO" and University
 
How so?
The function name isn't convertToFeet();
 
MBO, min qualification is VMBO
HBO, min qualification is HAVO
University, min qualification is VWO
 
suggesting we move to hassan support...
 
The function name is convertToFeet(miles:)
 
should have done that earlier
 
11:29 AM
I think it's fine here!
 
I'm not familiar with function pointers in Swift though.
 
there isn't that much more to say either way :p
 
We don't have the parenthesis in Objective-C.
 
@Vogel612 What are you supposed to do there?
 
So the method name is just: convertToFeetFromMiles:
 
11:30 AM
@rolfl codereview.stackexchange.com/a/57913/49350 you've got a typo in there "poentially"
 
@SimonAndréForsberg keep it out of main chat.
 
but I can't edit for a single character.. but... it's a typoooo
 
Is @rolfl awake already?!
That probably explains the typos.
 
@Vogel612 But isn't "Hassan Support" for... well... Hassan Support?
 
@nhgrif it's not about convertToFeet anymore, it's about abstract function pointers that I use for various things not working anymore if you need to name your arguments
 
11:31 AM
@Pimgd Thanks, fixed.
@skiwi yup
 
@Pimgd Not the first monkey-typo, you'd better get used to them...
 
@SimonAndréForsberg I am against reserving a whole chatroom full of possibilites for just "hassan support"
 
My tpyos are fwe and far beetwen
 
@rolfl The only way to shorten your Java 8 code is to shorten the variable names, so I think you did well there.
 
@SimonAndréForsberg Typooos... wobbles back and forth
 
11:32 AM
@Pimgd Why does having parameter names break it? convertToFeet(miles:) and convertToFeet(inches:) are two distinct functions. I don't understand how this breaks function pointers.
 
@Vogel612 Chat rooms are freely available for you to join or leave.... just don't go there if you don't want.
 
@nhgrif cause if you want to call them you need to put the argument name there?
 
@Vogel612 I am for having a chatroom for Hassan so that he doesn't have to pollute the main chat.
2
 
TTGTW
 
@SimonAndréForsberg Mean but painfully true
 
11:35 AM
@Pimgd Again, I'm not sure how function pointers work in Swift. In Objective-C, you don't have to know the argument names, so I'd guess you don't have to in Swift.
 
Yay, if we all star it, it will stay in the quote list on the right and we'll be sure to insult him. I feel mean now.
@nhgrif I dunno, I don't program in swift.
 
Yet you're willing to make judgments on it.
 
Pssst - don't tell anyone, but sometimes... I'm kind of a judgemental asshole.
Haven't found a fix for that yet =/
 
Objection!
 
Where does he keep a red card that big
 
11:40 AM
In his hand, obviously.
 
0
A: Working with Classes (inheriting), @ properties and Initialization

nhgrifThis code does what it is asked to do. But it can still be better. First of all, in init and factory methods, it is good to use instancetype as the return type rather than id. instancetype allows you to still return the correct type when you've subclassed, but it doesn't return the generic id ...

going to work
 
@nhgrif I just hate things that you'd call "gotcha's". Things that you need to keep remembering as "different" in a programming language. Things that will utterly stump you until you remember that one thing.
Crap like "4a" + 1 in Coldfusion being 1.16666667
How does that even work?!
 
@Pimgd Well, isn't that just obvious?
 
@skiwi Tell me
 
I have no clue
 
11:47 AM
It has to do with data type conversion.
 
Oh... I guess we are screwed now in Java future version
 
It tries to parse "4a" as a date since dates in coldfusion are strings
Normally that doesn't work
 
/**
* Write additional type-variable flags associated with methods and class symbols.
* This routine assumes that no more than (2^8 - 1) type-variables are declared by a given
* class/method. All flags are stored as a sequence of consecutive bytes in the
* TypeVariableMap attribute. If the input type-variable list is empty, no attribute is added.
*/
 
But "4a" is treated as "4 AM"
 
If a class or method has 256 type variables, then it will fail to work
 
11:48 AM
4 AM is then converted to a number, since it has to be added to. Since that's 4/24 hours of a day, you get 1/6.
Then it adds the 1.
@skiwi where's that from?
 
@Pimgd Java Project Valhalla repository, some compiler internal
@Pimgd That's awful
 

« first day (446 days earlier)      last day (3588 days later) »