Skip to content

Lambdas in CreateRandomHeightMap function#1

Open
Makinami wants to merge 3 commits intoCloudsfrom
develop
Open

Lambdas in CreateRandomHeightMap function#1
Makinami wants to merge 3 commits intoCloudsfrom
develop

Conversation

@Makinami
Copy link
Owner

One function of a larger object
We can assume that defined lambdas will not be necessary anywhere else in any foreseeable future
The main question is: is it ok, or should I declare proper methods and such?
Sam widzę kilka problemów z łapaniem lokalnych zmiennych, ale to jeszcze powinienem być wstanie ogarnąć lepiej

@Makinami Makinami requested a review from jantosi February 21, 2017 14:49
Copy link
Collaborator

@jantosi jantosi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like how you wanted to create some atomic functions and then compose them into larger operations. Please work a bit more on expressing your intent with naming and conventions so that another developer could pick these atoms and create a new composition with ease.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect use-case of ? : operator

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these auto variablename = ... lambdas could be refactored into declared methods on some util class. You don't need lambdas here, since these aren't brief, aren't used ad hoc and finally, variables holding these should be constants instead.

I can see the value of learning how to write proper lambdas. I would, however, write normal methods here.

auto average = [](std::initializer_list<float> list)
{
float sum = std::accumulate(std::cbegin(list), std::cend(list), 0.0,
[](auto&& a, auto&& b) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a perfect lambda: small, inline, extraction into a method would decrease simplicity. I would go even further and make it a one-liner

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filtering! Great use of lambdas 👍

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks familiar, function composition? I would extract composeFunctions(fn1, fn2)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realise why capture lists are needed in C++, but this makes the perfect case against them ;) Sooo long

Also, naming of this lambda is quite confusing; dividing what into what?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these following lines a sort of unit-test?

{
mImmediateContext->PSSetShaderResources(2, 1, &mLayerMapArraySRV);
return;
//return;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Committing commented-out code is a no-no

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to assume value 0 of -1-elements? If so, this needs to be expressed somewhere. Right now this looks like magic and could introduce hard-to-debug logic.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're not using sizeY from capture list anywhere in this lambda

Makinami added 2 commits February 24, 2017 18:45
- update VisualCppTools
- deprecate LoadShader function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments