IT/Software career thread: Invert binary trees for dollars.

Noodleface

A Mod Real Quick
37,961
14,508
OK I'm a bit confused with 2 java concepts so far

Can someone give a practical reason you'd use an anonymous class?

I don't understand lambda expressions, what is the point?
 

Deathwing

<Bronze Donator>
16,409
7,408
Both are very similar, especially since lambda expressions are also called anonymous functions.

They're good in places where you need some throwaway code that won't be used elsewhere. So, instead of writing up a formal declaration for a class or function, you can have the code essentially inline. This makes understanding code much easier because the person doesn't have to go figure out how FileWriterClass or UpdateWarn works.

I have no experience with anonymous classes, I'm not sure Python supports that 100%. But lambdas are useful from time to time. A bug I'm working on now, I'm trying to streamline scanning gigantic logs so that our system only has to read any log once. Some of the code that wants to scan a log might want to do something so simple with the information, I can replace formal function definitions with a lambda.
 

moontayle

Golden Squire
4,302
165
Someone else can correct me if I'm wrong but Anonymous classes allow you to create a customized instance of that class without having to go about the process of creating a separate custom class file or internal class to achieve the same results. Good example from Android is button clicks within an app. Implementation of what to do is handled through anonymous OnClickListener classes.

Code:
button.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
                 // Perform action on click
             }
         });

You almost certainly wouldn't want to create class files or internal classes for every button or instance of a Listener so for the most part you do it this way.

Lambdas take the above and basically drill it down to just the necessities.

Code:
button.setOnClickListener(v -> { // Perform action on click });

I use a lot of RxJava and it's extremely verbose without lambdas. The tricky part is learning the syntax to use lambdas without screwing up the code but it's pretty straightforward most of the time.
 

Tenks

Bronze Knight of the Realm
14,163
606
OK I'm a bit confused with 2 java concepts so far

Can someone give a practical reason you'd use an anonymous class?

I don't understand lambda expressions, what is the point?

AIC is a bit deprecated now since lambdas can deprecate it. But in general you'll use an AIC to define custom logic around boiler plate code. So if you have like

Code:
public abstract class DoSomething{
     public void execute(){
            //Do some boilerplate here
            this.myLogic()
            //Do other boilerplate
     }
    public abstract void myLogic();
}

Then you'd use it like

Code:
DoSomething ds = new DoSomething(){
     public void myLogic(){
           System.out.println("Wow this is so amazing");
     }
}

ds.execute();


Then for Lambdas you can start doing some really cool stuff revolving around reuse. Like I wrote some CRUD stuff which required some custom logic around it. However what it did for the CRUD method would go to different DAO's and things like that. So I just made it so the add/update/delete methods were all BiFunctions and I could pass in what they do as lambdas to the concrete instances of my generic class.
 

wilkxus

<Bronze Donator>
518
210

Can someone give a practical reason you'd use an anonymous class?



I don't understand lambda expressions, what is the point?

If you were explicitly tasked/asked with learning these new paradigms because you need to be thinking/problem solving debugging code with these paradigms, then it MIGHT be worth your while to read on. Otherwise you might not need to worry about it much until you encounter that code in your code base.



Since Oracle only relatively recently (since Java 8?) started adding Functional programming constructs so you might not need to bother at all?


I gather you are coming at this from a Comp-Eng background right? Perhaps some computer science terminology and theory might be helpfull to understand functional programming and "what the point" of some of the paradigms is.

Since you are working in the public/defense sphere you might be exposed to more programming paradigms than is usual in the private sector. Think of the computer languages as just TOOLs from a toolbox that you can use: different paradigms are different types of tools. No one tool is better than another per se, it is all relative depending on the problem you are trying to solve.


Programming Paradigms....


1) Imperative [ assembly, C, COBOL ...]
2) OOP [C++, Java, ADA etc...]
3) Functional [ LISP, Haskell, Erlang etc. ]
4) Logic [Prolog ... ] less common except for AI related stuff


Usually most people never touch 3) or 4) or even ADA, Pascal etc but ALL have their niche domains.....esp defense where a LOT of IT research starts... and lives on hidden for a loooong time =)


If you are coming from a Procedural programming background (C/assembly working on Firmware?) and moving to Java ( OOP) the concepts you are asking about come from the Functional Programming domain (not Java or the OOP domain, they are VERY recent additions to Java & C++ standards).

Functional programming concepts in question here:



* lambda functions (aka closures: they delay evaluation until they are CALLED.... they CLOSE over variables from their defining scope)

* Partial Function Application [ and currying]



It might help to think of passing functions as blocks of code with parameters where parameters can BE blocks of code (ie functions are first-class values) . See Suggested Reading for some good simple examples

[1] Have a peek at Wiki....
Currying - Wikipedia, the free encyclopedia
Partial application - Wikipedia, the free encyclopedia


....then read these.....



[2] Lambda Expressions in Java 8
[3] http://dzone.com/arcticles/functiona-programming-java-8

Browse more DrBobbs, it is not active anymore but still great programming theory & practical reference.

for PRACTICAL examples..... look @ work!



[4] Asking senior co-workers to show you example code in your code-base and guide you through would be the best next logical step.....

[5] Hopefully you find some code..... If there is no example code @ work.....then this is all probably TLDR right?


Examples I might give here would not be nearly as good as your own problems & code from work. Some umm I hope helpfull, unsolicited, advice from my personal experience:

Be sociable especially with the old geezers! They often know most/best. It is kind of like in the open source community.... do some leg work first, show interest and THEN anyone/everyone will be happy to help ya. Co-workers will be better than forums 99% of time since they know your domain AND code base well. Take time to find out who the EXPERT geezer is.....well worth the effort. Maybe you get lucky and find a good mentor!

So try to get some sample code from your actual code base, with an experienced co-worker in your group or from your client. Even go to the trouble to schedule a meeting for 30 min to walk through an example, it might help you come up to speed REALLY fast with LEAST amount of effort.


Hope that helps get you started.
 
Last edited:

Noodleface

A Mod Real Quick
37,961
14,508
I don't specifically need to learn it but I do need to learn Java. It was mixed in and I read about them a few times but didn't understand
 

Tenks

Bronze Knight of the Realm
14,163
606
AIC is just a way to define abstract/interface/override methods on the fly in-line with your code. Sometimes it makes the code readable sometimes it makes the code a mess.
 

Ao-

¯\_(ツ)_/¯
<WoW Guild Officer>
7,879
507
It got pretty lame about the time Noodle sacrificed his career to join a Defense Contractor.

Mists job sounds more interesting now.
I'd hope to that if I didn't have to move. But defense contractors don't like the cold. Except Orbital, but they're dumb.
 

Noodleface

A Mod Real Quick
37,961
14,508
It got pretty lame about the time Noodle sacrificed his career to join a Defense Contractor.

Mists job sounds more interesting now.
I mean I guess I could've just been a UEFI Firmware developer in a really niche role for the rest of my life
 

Dr Neir

Trakanon Raider
832
1,505
Ya, not understanding the choice option and seems to be riddled in this thread more than swiss cheese? Companies generally want an expert in the slot for lowest pay possible. Non-forced Job seekers (meaning those not fired/Laid off but those wanting more money or change) sometimes want out of the crappy situation, wont find too many companies willing to pay them to learn and catchup.

Intersecting Graph would show current salary limit vs available companies willing to hire with seekers past/current experience. There are a ton more options, Street Corner Hooker, Fluffer, or even burger monitor for a fortune 500 company but it comes down to required salary, benefits and personal benefits of the situation like location and change of daily office grind that force the seeker into limits selections based on current availability at the current time. Things can get old, change is needed. Sometimes when something shows up you have to weight the options to get out or sit there in that pot of boiling water hoping all will be fine.
Gone of days of employees staying at 1 company for multiple decades and even greater when you climb the pay scale.

Depending on current job and changes in the future, this has a greater possibility to be more hirable on the resume than hurtful if one wants to more on after this. Been many a time in interviews HR and TL have seen that on the resume and looked kindly on it, granted many have not worked in that sector and it still holds a special Awe with their no knowledge of it. Benefits to the seeker.

As in many jobs, if you want to learn something new and impress others on the internets, its in the realm of hobby or training to get into that next career. Not to mention, easier to present your work since its not from your employer's. You own it, can show it and make changes to it and will continue to own it after switching careers and companies.

Cutest-Beating-Dead-Horse-GIF.gif
 
  • 2Like
Reactions: 1 users

Big Phoenix

Pronouns: zie/zhem/zer
<Gold Donor>
44,675
93,370
I mean the pace is perfect for me. I just need to figure out how to appear busy


Or just disappear as much as possible. When I got back from Iraq I was completely useless as I was getting out in 8 months and my section had just gotten in a 5 new guys. Oh need to go down to mainside to turn in some paperwork or pickup some gear? be back in 3 hours.

and fuck EQIP.
 
Last edited:
  • 1Like
Reactions: 1 user

Rabkorik

Silver Knight of the Realm
158
39
I have a SQL Question.

Lets say I have the following record sets:

ID Code Code2
1 A A
1 A 0
1 A A
1 A 0

2 B 0
2 B 0
2 B C

How would I write something that would return if code=code2 then return those results, if not check for where Code2=0. The result set would look like this:

ID Code Code2
1 A A
1 A A

2 B 0
2 B 0
 

Cad

<Bronze Donator>
24,487
45,378
I have a SQL Question.

Lets say I have the following record sets:

ID Code Code2
1 A A
1 A 0
1 A A
1 A 0

2 B 0
2 B 0
2 B C

How would I write something that would return if code=code2 then return those results, if not check for where Code2=0. The result set would look like this:

ID Code Code2
1 A A
1 A A

2 B 0
2 B 0

Do you want it to return both sets, the ones where Code=Code2 and the ones where Code2=0, or really only return the Code2=0 ones if Code=Code2 doesn't return anything?
 

Rabkorik

Silver Knight of the Realm
158
39
Do you want it to return both sets, the ones where Code=Code2 and the ones where Code2=0, or really only return the Code2=0 ones if Code=Code2 doesn't return anything?

Only if Code=Code2 doesnt return anything check for Code2=0
 

Cad

<Bronze Donator>
24,487
45,378
just do
Code:
select * from table_name where code=code2
JOIN
select * from table_name where code2=0 and (select count(*) from table_name where code=code2) = 0

or similar depending on your syntax
 
  • 1Like
Reactions: 1 user

Vinen

God is dead
2,783
489
just do
Code:
select * from table_name where code=code2
JOIN
select * from table_name where code2=0 and (select count(*) from table_name where code=code2) = 0

or similar depending on your syntax

Lawyer with programming and database skills is terrifying.
 
  • 1Like
Reactions: 1 user

Noodleface

A Mod Real Quick
37,961
14,508
Picked up Ada and Java. First assignment is in Java which is nice, but no one documented how to setup the code base and IDE so I'm having a ton of fun.

I am the youngest dude here for sure.