Looking for complex example of OPA code/rules - oracle-policy-automation

Can anyone point me to an example of a decent sized chunk of OPA code (i.e. a rule .docx)? I'm having a terrible time Googling, as all I get are "This is why OPA is so great and what it can do" results with tiny snippets of code. I've been told to figure out an OPA solution to an issue and have never used it before. I've actually gotten pretty far but I keep running into little obstacles that I think a solid example of a complex rule with many conditions would really help me solve.

Related

Web editing background - getting accredited in coding

I have a background in intranet/Web content management, mostly in SharePoint. My current job requires a pretty sound knowledge of HTML and I've managed to get to grips with the essential points but would really like some proper training and possibly accreditation. I'd really like to learn more about programming and CSS but think I really need my ducks in a row on this first (but happy to be proved wrong!!) There are a lot of courses out there and I wondered if there were any some might recommend. I'm after part time study and don't have a huge wad of cash to throw at this unfortunately. Any suggestions would be much appreciated!
There are many pages to learn HTML, CSS, ...
Google will list much more than we could ever post here.
Please do some research.
But have a look:
https://www.w3schools.com/html/
https://www.codeschool.com/learn/html-css
...

The hunt for a CSS attribute-editable Interactive User Interface Learning Tool

I am attempting to learn css attribute relationships. With my current knowledge, I would venture to say that there are only about 30 or so attributes that the majority of web pages are built around, but how you match them up is what gives one page a cleaner look, better functionality, and an overall better experience for the user. Currently I am getting feedback that the 'only' way to learn is by a combination of experience and looking at examples of implementation(s) on webpages that have the feature(s) I want, and trying to replicate. I think this is too time consuming, and not an effective tool for someone wanting to develop a solid approach to CSS. Is/are there tools that you have used similar to any of the below that help you understand the interaction of the attributes for basic manipulation of semantic markup?
Current tools that have GUIs to allow quick feedback of attribute/element manipulation:
JSFIDDLE : An online platform for viewing HTML, JS, CSS, and the result in one window, allowing for common shared code.
Button Maker : Dynamic CSS/HTML generation for a graphical button.
SourceTree : For understanding repository structure for Git,
Mercurial and SVN version control systems.
Eclipse : An IDE with 'desktop' organization of multiple implementations, code, and information panes.
CodingBat : An online console for learning Python or Java by 'snippet' coding and viewing results of different passed parameters.
Codeyear / CodeAcademy : An online IDE to allow for both 'snippet' coding and viewing CSS/HTML/JS/results in several structured learning paths.
Specifically, I would like to learn the relationships of postion based styles, such as fixed, float and such.
For me, the best way to learn: Think up of something you want to make. Make it. Go through the process of finding out what works and what doesn't. Figure out how to fix it. Fix it. Be amazed at how crappy the result is. Repeat.
You won't learn all the little tricks by looking at independent examples. You won't learn much by "looking at" anything. Do it. Once you have a basic grasp of what's going on, make something. Copy something. Time consuming? yes, sure... if you say so. Experience comes with time.
The thing with copying other people is that you don't know the process they went through. Why did they do something a certain way? Is it even right? Just because somebody put it online doesn't mean it's any good.
So specifically, what function do you want to implement? Google that, read all the different ways people do it. Find one that you like, implement it. Tweak it. If you don't understand, look into that.
I think there's a term for when you're trying to find something, you go from one (related) thing to another until you forget your original issue... That's bad when you need to be productive. It's perfectly fine here, where you just want to learn everything.
For some things, it's important to have structure. Once you learn the basics, I think having some sort of structure or system will just slow you down. I like to go at it and solve a problem, learning as I go. When I'm trying to figure something out, I have nothing but Notepad and Chrome with a lot of Google search results tabs open. You don't need all these GUI tools. Sure they might make your development go a little faster with their auto complete or error warnings, but what's your rush?
Don't spend so much time finding the perfect set of tools that you never get to the thing you were finding those tools for. Just do it.

How to force myself to follow naming and other conventions

I believe, I program good, at least my code produces results...
But I feel I have drawback... I hardly follow any naming conventions... neither for variables.. nor for methods... nor for classes... nor for tables, columns, SPs... Further to this, I hardly comment anything while programming...
I always think that, Let me first see the results and then I will come and correct the var names and other things later... (Thanks to visual studio's reflection here)... But the later does not come...
So, I need tips, to force myself to adopt to the practice of following naming conventions, and commenting...
Edit : I totally understand the ill effects of my practice, and I also know, that it is bad... My question is how do I force myself to follow the discipline...
Are you able to ask others for code reviews? Or even try pair programming? Both of those can really help you to do things you know you really should do.
Also, depending on your language/platform, there may well be lint-like tools you can run to check your code's health.
I hope you get to spend a few years working on code produced by someone else that has the same poor coding practices that you have. Only then will you truly understand how poor your code really is. Code that "works" is the bare minimum, writing code so that it is easy to to support, extend and maintain is where the genius of a good programmer is.
My gut tells me that your code is probably not as good as you think if you have no standards. You really just have to pick something, and stick to it. Being haphazard in coding style probably means you are haphazard in logic, which probably means you have a lot of bugs, and unexpected results in your code that will be hard to deduce later. Good luck.
Just remember the general coding guidelines you need to follow. And as you write the code write as per the guidelines with proper variable naming conventions for variables and methods and have function headers. Dont think whether your code will work or not, and code as per the guidelines.
Comments can be added later, but the naming conventions has to be followed even while doing a proof of concept.
Write your code with a confidence that its going to work.
Have your code reviewed by your peers, and also you can use Fxcop for static code findings.
Best of all, your code should work and should do what it's supposed to. It's what you get paid for.
However, if it is not readable, then it will fade into existence, because in time you will not remember what it does. To avoid this, refactor and document your code as soon as it works. As a rule of thumb, you should not be satisfied with your work before it is documented properly. For each method you write, this should not take too much time. But the longer you wait, the more time it will consume to figure out what your code was supposed to be doing.
I know the best way of all is to document before writing, but that won't work with cowboy coders. The other way around might be a good alternative, because readable and good documented code shows off a developer's skills.
This is a matter of coding discipline. If you want to prototype something and then throw the code away, this is acceptable. However, the instant you need to reuse or debug your code, you will regret having no comments and poor method/variable name choices.
While you are working with the code now, you know what it is doing. In a few months to a year, you will not remember everything so clearly. Then, you will likely regret not commenting your code and not choosing good names.
Consider, too, if someone else were to read your code, how easy would it be to understand?
Running something like StyleCop (if you're writing C#) can go some way towards this. It won't warn you about everything, but you can use it to make sure your methods have documentation comments etc.
However, as others have said coding discipline is something that has to come from within, not without.
If you want to change something about yourself, you need to motivate yourself to change it. That's one of the "rules of life."
This isn't really something Stack Overflow can help you with. I suppose that a good suggestion to build up some motivation is finding yourself a job as a developer and see how far your development habits lead you...
-Carlos Nunez

Judging competency - does one swallow make a summer?

Whilst working on some generally horrible Javascript code this morning, I came across the following (in multiple places):
// make moveAmount negative
moveAmount = moveAmount - (moveAmount * 2);
I sit directly across from the guy that wrote this; he's been a developer here for seven years. I, on the other hand have just started, am pretty junior and don't claim to know jack.
Nevertheless it has got me wondering about the guy's contortions of simple logic after so many years developing software.
My question is what view others here might take of the overall competancy of a developer that wrote this (3 weeks ago), or does it even reflect at all?
Would anyone point out the convolution?
I, myself, work in constant dread that such judgements be made of me.
Simple solution: Show him the line of code and ask why he did it. It's an opportunity for both of you to learn something. Maybe there was a bug in a browser or some other issue (rounding comes to mind) so the code might break without this. Or he made a mistake. Either way, asking will clear this up.
And while you're right that other people will judge you from the code they see from you, that is not the only thing they take into consideration (and if it is, then you're working at the wrong place -- leave while you're still sane). They will also see when you're polite, curious, helpful.
These things count more than the code you write: Code can be fixed much more easily than angry co-workers.
Your example may be poor code, but I've seen worse (after all, there are circumstances where it will work; some code can't even say that). I think the question you're really asking is: is there any line of code so awful that it means the developer can be deemed incompetent on the basis of that one line?
I say no. I have two children who were terrible sleepers as babies. I've come to work with the flu. I've been at work in death-march mode where I've been working twenty hours in a row. In such circumstances anyone can write a terrible line of code. (This is why such circumstances should be avoided.)
Granted, I would hope I would spot the dreadful code later, and fix it.
Well it works so you would just look like a p**** if you told him that you dislike that code and probably rightly so :) Then again he might have done that code 7 years ago as the very first JavaScript he wrote, but seriously never judge someone from just ONE LINE of code.
Regarding the fear of judgement, relax. It's true, we're all going to be judged by someone at some point, whether it's some pointy-haired boss or maleveolent little upstart. The main thing to get to grips with, I think, is how to get something useful out of every such encounter.
Obviously, there are going to be people griping about things for the sake of it, but you'll also find many similar situations where there's something to be learned.
The suggestion above to start a dialogue with your co-worker is excellent; it may directly feed into just such an encounter, from which either, or both of you, may learn something important.
It's tempting to find one example and generalize about a developer, but unless he has a track record of this sort of nonsense, I would consider it an isolated incident. Simply ask him why he didn't write :
moveAmount = moveAmount * (-1)
this behavior is different from
mountAmount = -moveAmount in the case where 2*moveAmount may cause an overflow if moveAmount was big enough (like 2^32-1 for example).
I don't know if that was his intention though.
Since he wrote it 3 weeks ago, I would say he should be open to criticism for this line. It shows an immaturity that is really inexcusable after 7 years of working professionally.
If he would have at least done this:
moveAmount -= moveAmount * 2;
He would have gotten less flack. It at least shows that he's aware of the other operators and is making some effort to make things more readable.
I don't think that you can always judge people with one line, but the code can tell you so much about a person's aptitude that one line can tell a lot about a person.
I say it will depend on the swallow. If isolated, the line of code you've shown is something I would expect from an exhausted programmer, even if a very competent one. It is an example of something just not very clever and tired people do not so clever things. If, on the other hand that kind of code appears frequently then probably you're working with someone with a twisted mind.
Things that are obvious indications of a bad programmer are related to bad practices. Good programmers will not make huge methods. Even tired, they will try to keep their types loosely coupled. They will avoid exposing public fields instead of exposing them through accessors or properties. They will try inheritance and aggregation as forms of code reuse rather than repeatedly doing copy-paste... The list is long. Those are the kinds of swallows that lead me to almost instantly feel it is summer. :-)
If he wrote that when he was first beginning, he gets a pass. If he wrote that recently, he gets a thumbs down from me. The overall competency of the developer is definitely suspect.
Others are saying you can't judge a developer by one line of code, but I say it can certainly cast doubt upon his competence. I'm not suggesting you jump to conclusions, but that type of code is certainly evidence of a mediocre developer at best.
... and as for it being related to being overtired or stressed or whatever... the bottom line is that code quality is important. If he wrote a one-liner like this, what else may have been written that doesn't stand out so easily?

What is the best approach to take when you can't figure something out, and you have no one to ask?

The second part of that question is key. If you are one of a few programmers, and after banging your head on your keyboard for endless nights you can't figure something out, with no one else in your organization to ask, what do you do? Not having someone to ask has more to do with the fact that it would take too long to bring them up to speed to even have them assess the problem. Are these the instances where you have uncomfortable conversations with management and tell them a third-party contractor with more experience will be required?
There is a time and place when everybody hits a problem where there doesn't seem an obvious way out.
1) Ask yourself if you are the first person ever to solve this - if not, then there is likely to be an answer out there. Try Google, SO etc.
2) Take a break and try and do something else for a while - it's amazing what a few hours away from the keyboard and thinking about something else can do.
3) Try talking about the problem to someone else, even if they aren't technical - sometimes the process of explaining a problem to someone who isn't technical or involved can lead you to the right answer or an approach from a different angle.
4) Admit it's harder than you had envisaged or you are stuck. A good boss will help you get to the right outcome, for both you and their business. Make them aware of the effort put in and the conclusions and decisions you've made to date.
5) If all else fails, help your boss choose the contractor as you'll probably have to maintain their code :-)
My favorite is rubber ducky debugging, explained here:
http://lists.ethernal.org/oldarchives/cantlug-0211/msg00174.html
We called it the Rubber Duck method of
debugging. It goes like this:
1) Beg, borrow, steal, buy, fabricate
or otherwise obtain a rubber duck
(bathtub variety)
2) Place rubber duck
on desk and inform it you are just
going to go over some code with it,
if that's all right.
3) Explain to the
duck what you code is supposed to do,
and then go into detail and explain
things line by line
4) At some point
you will tell the duck what you are
doing next and then realise that
that is not in fact what you are
actually doing. The duck will sit
there serenely, happy in the knowledge
that it has helped you on your way.
Works every time. Actually, if you
don't have a rubber duck you could at
a pinch ask a fellow programmer or
engineer to sit in.
Andy
Some times if I can't come up with a solution it might be because I am headed the wrong path with my approach to solving the problem.
It helps me a great deal to not think about the problem for a little bit. Coming back to it after a break can give one fresh insight that might help find a solution.
Depending on the problem sometimes I develop one-off apps to test/work with that particular feature/bug/whatever without all of the other pre-conditions and dependencies that exist in the project (and could be affecting the result).
Try redefining the problem. Sometimes you can rework the software you're writing so that you don't encounter the problem that you're trying to solve. Somtimes it's not a problem with your solution, but instead the state of the software that you're trying to implement it in.
First I google
And if that doesn't help I try to split the problem into parts I can solve. Usually the insight I get doing those parts will enlighten me sufficiently so I can take a new stab at the difficult part.
I like to start working on the easiest bits first. So what if you can't figure out how to find the optimised path algorithm in your map? Just start by writing the flood-fill drawing code. Then do the AI routines for combat, after all they need to get done as well. Then while you are working on the weather simulator, you will realise that your subconscious has been working out the details for the pathing algorithm while you slept.
I faced this situation for an entire project in which I was the only programmer on the job, responsible for architecture all the way down to maintenance.
I dealt with it by aggressive use of Google and programming Q&A sites, though I didn't have SO at the time (resorted to Yahoo! Answers a couple of times). Most of the time I wouldn't find exactly what I needed, and I had to use my brain and do some hard-core trouble-shooting to solve most problems.
When you get absolutely stuck behind a brick wall, you need to come up with workarounds that are satisfactory for your end users. Chances are you won't be able to make everything work by sheer force of programming.
I agree with another answer here that sometimes getting up and walking away from a problem will often provide you with flashes of insight that would never occur to you while you're behind the keyboard. I have often had my most brilliant ideas come to me while driving or in the shower.